repo
stringclasses
1k values
file_url
stringlengths
96
373
file_path
stringlengths
11
294
content
stringlengths
0
32.8k
language
stringclasses
1 value
license
stringclasses
6 values
commit_sha
stringclasses
1k values
retrieved_at
stringdate
2026-01-04 14:45:56
2026-01-04 18:30:23
truncated
bool
2 classes
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/model/io/XMLSchemaFileImportException.java
plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/model/io/XMLSchemaFileImportException.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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.apache.directory.studio.schemaeditor.model.io; /** * This class represents the XMLSchemaFileImportException. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class XMLSchemaFileImportException extends Exception { private static final long serialVersionUID = 1L; /** * Creates a new instance of XMLSchemaFileImportException. * * @param message * the message */ public XMLSchemaFileImportException( String message ) { super( message ); } /** * Creates a new instance of XMLSchemaFileImportException. * * @param message * the message * @param cause * the cause */ public XMLSchemaFileImportException( String message, Exception cause ) { super( message, cause ); } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/model/io/GenericSchemaConnector.java
plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/model/io/GenericSchemaConnector.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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.apache.directory.studio.schemaeditor.model.io; import java.text.ParseException; import java.util.ArrayList; import java.util.List; import javax.naming.directory.SearchControls; import org.apache.directory.api.ldap.model.constants.LdapConstants; import org.apache.directory.api.ldap.model.constants.SchemaConstants; import org.apache.directory.api.ldap.model.entry.Attribute; import org.apache.directory.api.ldap.model.entry.Entry; import org.apache.directory.api.ldap.model.entry.Value; import org.apache.directory.api.ldap.model.exception.LdapException; import org.apache.directory.api.ldap.model.exception.LdapInvalidAttributeValueException; import org.apache.directory.api.ldap.model.schema.AttributeType; import org.apache.directory.api.ldap.model.schema.LdapSyntax; import org.apache.directory.api.ldap.model.schema.MatchingRule; import org.apache.directory.api.ldap.model.schema.ObjectClass; import org.apache.directory.api.ldap.model.schema.parsers.AttributeTypeDescriptionSchemaParser; import org.apache.directory.api.ldap.model.schema.parsers.LdapSyntaxDescriptionSchemaParser; import org.apache.directory.api.ldap.model.schema.parsers.MatchingRuleDescriptionSchemaParser; import org.apache.directory.api.ldap.model.schema.parsers.ObjectClassDescriptionSchemaParser; import org.apache.directory.studio.common.core.jobs.StudioProgressMonitor; import org.apache.directory.studio.connection.core.Connection; import org.apache.directory.studio.connection.core.Utils; import org.apache.directory.studio.connection.core.io.ConnectionWrapper; import org.apache.directory.studio.connection.core.io.api.StudioSearchResultEnumeration; import org.apache.directory.studio.schemaeditor.PluginUtils; import org.apache.directory.studio.schemaeditor.model.Project; import org.apache.directory.studio.schemaeditor.model.Schema; import org.eclipse.osgi.util.NLS; /** * A Generic Schema Connector, suitable for all LDAP servers. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class GenericSchemaConnector extends AbstractSchemaConnector implements SchemaConnector { /** * {@inheritDoc} */ public void importSchema( Project project, StudioProgressMonitor monitor ) throws SchemaConnectorException { monitor.beginTask( Messages.getString( "GenericSchemaConnector.FetchingSchema" ), 1 ); //$NON-NLS-1$ List<Schema> schemas = new ArrayList<Schema>(); project.setInitialSchema( schemas ); ConnectionWrapper wrapper = project.getConnection().getConnectionWrapper(); SearchControls constraintSearch = new SearchControls(); constraintSearch.setSearchScope( SearchControls.OBJECT_SCOPE ); constraintSearch.setReturningAttributes( new String[] { SchemaConstants.ATTRIBUTE_TYPES_AT, SchemaConstants.COMPARATORS_AT, SchemaConstants.DIT_CONTENT_RULES_AT, SchemaConstants.DIT_STRUCTURE_RULES_AT, SchemaConstants.LDAP_SYNTAXES_AT, SchemaConstants.MATCHING_RULES_AT, SchemaConstants.MATCHING_RULE_USE_AT, SchemaConstants.NAME_FORMS_AT, SchemaConstants.NORMALIZERS_AT, SchemaConstants.OBJECT_CLASSES_AT, SchemaConstants.SYNTAX_CHECKERS_AT } ); String schemaDn = getSubschemaSubentry( wrapper, monitor ); StudioSearchResultEnumeration answer = wrapper.search( schemaDn, "(objectclass=subschema)", constraintSearch, //$NON-NLS-1$ DEREF_ALIAS_METHOD, HANDLE_REFERALS_METHOD, null, monitor, null ); if ( answer != null ) { try { // Looping the results while ( answer.hasMore() ) { // Creating the schema Schema schema = new Schema( "schema" ); //$NON-NLS-1$ schema.setProject( project ); schemas.add( schema ); getSchema( schema, wrapper, answer.next().getEntry(), monitor ); } } catch ( SchemaConnectorException e ) { throw e; } catch ( Exception e ) { throw new SchemaConnectorException( e ); } } monitor.worked( 1 ); } /** * {@inheritDoc} */ public boolean isSuitableConnector( Connection connection, StudioProgressMonitor monitor ) { return getSubschemaSubentry( connection.getConnectionWrapper(), monitor ) != null; } private static String getSubschemaSubentry( ConnectionWrapper wrapper, StudioProgressMonitor monitor ) { SearchControls constraintSearch = new SearchControls(); constraintSearch.setSearchScope( SearchControls.OBJECT_SCOPE ); constraintSearch.setReturningAttributes( new String[] { "subschemaSubentry" } ); //$NON-NLS-1$ StudioSearchResultEnumeration answer = wrapper.search( "", LdapConstants.OBJECT_CLASS_STAR, constraintSearch, //$NON-NLS-1$ //$NON-NLS-2$ DEREF_ALIAS_METHOD, HANDLE_REFERALS_METHOD, null, monitor, null ); if ( answer != null ) { try { if ( answer.hasMore() ) { Entry searchResult = answer.next().getEntry(); Attribute subschemaSubentryAttribute = searchResult.get( "subschemaSubentry" ); //$NON-NLS-1$ if ( subschemaSubentryAttribute == null ) { return null; } if ( subschemaSubentryAttribute.size() != 1 ) { return null; } String subschemaSubentry = null; try { subschemaSubentry = subschemaSubentryAttribute.getString(); } catch ( LdapInvalidAttributeValueException e ) { return null; } return subschemaSubentry; } } catch ( LdapException e ) { monitor.reportError( e ); } } return null; } private static void getSchema( Schema schema, ConnectionWrapper wrapper, Entry entry, StudioProgressMonitor monitor ) throws SchemaConnectorException { // The counter for parser exceptions int parseErrorCount = 0; Attribute attributeTypesAttribute = entry.get( SchemaConstants.ATTRIBUTE_TYPES_AT ); if ( attributeTypesAttribute != null ) { for ( Value value : attributeTypesAttribute ) { try { AttributeTypeDescriptionSchemaParser parser = new AttributeTypeDescriptionSchemaParser(); parser.setQuirksMode( true ); AttributeType atd = parser.parse( value.getString() ); AttributeType impl = new AttributeType( atd.getOid() ); impl.setNames( atd.getNames().toArray( new String[0] ) ); impl.setDescription( atd.getDescription() ); impl.setSuperiorOid( atd.getSuperiorOid() ); impl.setUsage( atd.getUsage() ); impl.setSyntaxOid( atd.getSyntaxOid() ); impl.setSyntaxLength( atd.getSyntaxLength() ); impl.setObsolete( atd.isObsolete() ); impl.setCollective( atd.isCollective() ); impl.setSingleValued( atd.isSingleValued() ); impl.setUserModifiable( atd.isUserModifiable() ); impl.setEqualityOid( atd.getEqualityOid() ); impl.setOrderingOid( atd.getOrderingOid() ); impl.setSubstringOid( atd.getSubstringOid() ); impl.setSchemaName( schema.getSchemaName() ); // Active Directory hack if ( impl.getSyntaxOid() != null && "OctetString".equalsIgnoreCase( impl.getSyntaxOid() ) ) //$NON-NLS-1$ { impl.setSyntaxOid( SchemaConstants.OCTET_STRING_SYNTAX ); } schema.addAttributeType( impl ); } catch ( ParseException e ) { // Logging the exception and incrementing the counter PluginUtils.logError( "Unable to parse the attribute type.", e ); //$NON-NLS-1$ parseErrorCount++; } } } Attribute objectClassesAttribute = entry.get( SchemaConstants.OBJECT_CLASSES_AT ); if ( objectClassesAttribute != null ) { for ( Value value : objectClassesAttribute ) { try { ObjectClassDescriptionSchemaParser parser = new ObjectClassDescriptionSchemaParser(); parser.setQuirksMode( true ); ObjectClass ocd = parser.parse( value.getString() ); ObjectClass impl = new ObjectClass( ocd.getOid() ); impl.setNames( ocd.getNames().toArray( new String[0] ) ); impl.setDescription( ocd.getDescription() ); impl.setSuperiorOids( ocd.getSuperiorOids() ); impl.setType( ocd.getType() ); impl.setObsolete( ocd.isObsolete() ); impl.setMustAttributeTypeOids( ocd.getMustAttributeTypeOids() ); impl.setMayAttributeTypeOids( ocd.getMayAttributeTypeOids() ); impl.setSchemaName( schema.getSchemaName() ); schema.addObjectClass( impl ); } catch ( ParseException e ) { // Logging the exception and incrementing the counter PluginUtils.logError( "Unable to parse the object class.", e ); //$NON-NLS-1$ parseErrorCount++; } } } Attribute ldapSyntaxesAttribute = entry.get( SchemaConstants.LDAP_SYNTAXES_AT ); if ( ldapSyntaxesAttribute != null ) { for ( Value value : ldapSyntaxesAttribute ) { try { LdapSyntaxDescriptionSchemaParser parser = new LdapSyntaxDescriptionSchemaParser(); parser.setQuirksMode( true ); LdapSyntax lsd = parser.parse( value.getString() ); LdapSyntax impl = new LdapSyntax( lsd.getOid() ); impl.setDescription( lsd.getDescription() ); impl.setNames( new String[] { lsd.getDescription() } ); //impl.setObsolete( lsd.isObsolete() ); impl.setHumanReadable( true ); impl.setSchemaName( schema.getSchemaName() ); schema.addSyntax( impl ); } catch ( ParseException e ) { // Logging the exception and incrementing the counter PluginUtils.logError( "Unable to parse the syntax.", e ); //$NON-NLS-1$ parseErrorCount++; } } } // if online: assume all received syntaxes in attributes are valid -> create dummy syntaxes if missing for ( AttributeType at : schema.getAttributeTypes() ) { String syntaxOid = at.getSyntaxOid(); if ( ( syntaxOid != null ) && ( schema.getSyntax( syntaxOid ) == null ) ) { LdapSyntax impl = new LdapSyntax( syntaxOid ); impl.setSchemaName( schema.getSchemaName() ); String oidDescription = Utils.getOidDescription( syntaxOid ); impl.setDescription( oidDescription != null ? oidDescription : "Dummy" ); //$NON-NLS-1$ impl.setNames( new String[] { impl.getDescription() } ); schema.addSyntax( impl ); } } Attribute matchingRulesAttribute = entry.get( SchemaConstants.MATCHING_RULES_AT ); if ( matchingRulesAttribute != null ) { for ( Value value : matchingRulesAttribute ) { try { MatchingRuleDescriptionSchemaParser parser = new MatchingRuleDescriptionSchemaParser(); parser.setQuirksMode( true ); MatchingRule mrd = parser.parse( value.getString() ); MatchingRule impl = new MatchingRule( mrd.getOid() ); impl.setDescription( mrd.getDescription() ); impl.setNames( mrd.getNames().toArray( new String[0] ) ); impl.setObsolete( mrd.isObsolete() ); impl.setSyntaxOid( mrd.getSyntaxOid() ); impl.setSchemaName( schema.getSchemaName() ); schema.addMatchingRule( impl ); } catch ( ParseException e ) { // Logging the exception and incrementing the counter PluginUtils.logError( "Unable to parse the matching rule.", e ); //$NON-NLS-1$ parseErrorCount++; } } } // if online: assume all received matching rules in attributes are valid -> create dummy matching rules if missing for ( AttributeType at : schema.getAttributeTypes() ) { String equalityName = at.getEqualityOid(); String orderingName = at.getOrderingOid(); String substrName = at.getSubstringOid(); checkMatchingRules( schema, equalityName, orderingName, substrName ); } // Showing an error if ( parseErrorCount > 0 ) { if ( parseErrorCount == 1 ) { throw new SchemaConnectorException( Messages.getString( "GenericSchemaConnector.OneSchemaElementCouldNotBeParsedError" ) ); //$NON-NLS-1$ } else { throw new SchemaConnectorException( NLS.bind( Messages.getString( "GenericSchemaConnector.MultipleSchemaElementsCouldNotBeParsedError" ), //$NON-NLS-1$ parseErrorCount ) ); } } } private static void checkMatchingRules( Schema schema, String... matchingRuleNames ) { for ( String matchingRuleName : matchingRuleNames ) { if ( ( matchingRuleName != null ) && ( schema.getMatchingRule( matchingRuleName ) == null ) ) { MatchingRule impl = new MatchingRule( matchingRuleName ); impl.setSchemaName( schema.getSchemaName() ); impl.setDescription( "Dummy" ); //$NON-NLS-1$ impl.setNames( new String[] { matchingRuleName } ); schema.addMatchingRule( impl ); } } } /** * {@inheritDoc} */ public void exportSchema( Project project, StudioProgressMonitor monitor ) throws SchemaConnectorException { // TODO Auto-generated method stub } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/model/io/AbstractSchemaConnector.java
plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/model/io/AbstractSchemaConnector.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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.apache.directory.studio.schemaeditor.model.io; import org.apache.directory.studio.common.core.jobs.StudioProgressMonitor; import org.apache.directory.studio.connection.core.Connection; import org.apache.directory.studio.connection.core.Connection.AliasDereferencingMethod; import org.apache.directory.studio.connection.core.Connection.ReferralHandlingMethod; /** * This class represents an AbstractSchemaConnector and implements SchemaConnector. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public abstract class AbstractSchemaConnector implements SchemaConnector { protected static final AliasDereferencingMethod DEREF_ALIAS_METHOD = AliasDereferencingMethod.ALWAYS; protected static final ReferralHandlingMethod HANDLE_REFERALS_METHOD = ReferralHandlingMethod.FOLLOW; /** The name */ private String name; /** The ID */ private String id; /** The description */ private String description; /** * {@inheritDoc} */ public String getDescription() { return description; } /** * {@inheritDoc} */ public String getId() { return id; } /** * {@inheritDoc} */ public String getName() { return name; } /** * {@inheritDoc} */ public boolean isSuitableConnector( Connection connection, StudioProgressMonitor monitor ) { return false; } /** * {@inheritDoc} */ public void setDescription( String description ) { this.description = description; } /** * {@inheritDoc} */ public void setId( String id ) { this.id = id; } /** * {@inheritDoc} */ public void setName( String name ) { this.name = name; } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/model/io/ProjectsExporter.java
plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/model/io/ProjectsExporter.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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.apache.directory.studio.schemaeditor.model.io; import java.util.List; import org.apache.directory.studio.connection.core.Connection; import org.apache.directory.studio.schemaeditor.model.Project; import org.apache.directory.studio.schemaeditor.model.ProjectType; import org.apache.directory.studio.schemaeditor.model.Schema; import org.dom4j.Branch; import org.dom4j.Document; import org.dom4j.DocumentHelper; import org.dom4j.Element; /** * This class is used to export Project(s) into the XML Format. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class ProjectsExporter { // The tags private static final String PROJECT_TAG = "project"; //$NON-NLS-1$ private static final String PROJECTS_TAG = "projects"; //$NON-NLS-1$ private static final String NAME_TAG = "name"; //$NON-NLS-1$ private static final String TYPE_TAG = "type"; //$NON-NLS-1$ private static final String CONNECTION_TAG = "connection"; //$NON-NLS-1$ private static final String SCHEMA_CONNECTOR_TAG = "schemaConnector"; //$NON-NLS-1$ private static final String SCHEMA_BACKUP_TAG = "schemaBackup"; //$NON-NLS-1$ /** * Converts the given project to its representation * in Dom4J Document. * * @param project * the project to convert * @return * the corresponding Dom4j Document representation */ public static Document toDocument( Project project ) { // Creating the Document Document document = DocumentHelper.createDocument(); // Adding the project addProject( project, document ); return document; } /** * Converts the given projects to their representation * in Dom4J Document. * * @param projects * the projects to convert * @return * the corresponding Dom4j Document representation */ public static Document toDocument( Project[] projects ) { // Creating the Document Document document = DocumentHelper.createDocument(); Element projectsElement = document.addElement( PROJECTS_TAG ); if ( projects != null ) { for ( Project project : projects ) { addProject( project, projectsElement ); } } return document; } /** * Add the XML representation of the given project * to the given branch * * @param project * the project * @param branch * the branch */ private static void addProject( Project project, Branch branch ) { Element element = branch.addElement( PROJECT_TAG ); if ( project != null ) { // Name String name = project.getName(); if ( ( name != null ) && ( !name.equals( "" ) ) ) //$NON-NLS-1$ { element.addAttribute( NAME_TAG, name ); } // Type ProjectType type = project.getType(); if ( type != null ) { element.addAttribute( TYPE_TAG, type.toString() ); } // If project is an Online Schema Project if ( type.equals( ProjectType.ONLINE ) ) { // Connection ID Connection connection = project.getConnection(); if ( connection != null ) { element.addAttribute( CONNECTION_TAG, connection.getId() ); } // Schema Connection ID SchemaConnector schemaConnector = project.getSchemaConnector(); if ( schemaConnector != null ) { element.addAttribute( SCHEMA_CONNECTOR_TAG, project.getSchemaConnector().getId() ); } // Schema Backup Element schemaBackupElement = element.addElement( SCHEMA_BACKUP_TAG ); List<Schema> backupSchemas = project.getInitialSchema(); if ( backupSchemas != null ) { XMLSchemaFileExporter.addSchemas( backupSchemas.toArray( new Schema[0] ), schemaBackupElement ); } } // Schemas XMLSchemaFileExporter .addSchemas( project.getSchemaHandler().getSchemas().toArray( new Schema[0] ), element ); } } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/model/io/SchemaConnectorException.java
plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/model/io/SchemaConnectorException.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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.apache.directory.studio.schemaeditor.model.io; /** * This class represents the SchemaConnectorException. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class SchemaConnectorException extends Exception { private static final long serialVersionUID = 1L; public SchemaConnectorException() { super(); } public SchemaConnectorException( String message, Throwable throwable ) { super( message, throwable ); } public SchemaConnectorException( String message ) { super( message ); } public SchemaConnectorException( Throwable throwable ) { super( throwable ); } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/Messages.java
plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/Messages.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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.apache.directory.studio.schemaeditor.view; import java.util.MissingResourceException; import java.util.ResourceBundle; /** * This class get messages from the resources file. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class Messages { /** The resource name */ private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle.getBundle( Messages.class.getPackage().getName() + ".messages" ); /** * Get back a message from the resource file given a key * * @param key The key associated with the message * @return The found message */ public static String getString( String key ) { try { return RESOURCE_BUNDLE.getString( key ); } catch ( MissingResourceException e ) { return '!' + key + '!'; } } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/SchemaEditorTypeLabelDecorator.java
plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/SchemaEditorTypeLabelDecorator.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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.apache.directory.studio.schemaeditor.view; import org.apache.directory.api.ldap.model.schema.AttributeType; import org.apache.directory.api.ldap.model.schema.ObjectClass; import org.apache.directory.api.ldap.model.schema.ObjectClassTypeEnum; import org.apache.directory.api.ldap.model.schema.UsageEnum; import org.apache.directory.studio.schemaeditor.Activator; import org.apache.directory.studio.schemaeditor.PluginConstants; import org.apache.directory.studio.schemaeditor.view.wrappers.AttributeTypeWrapper; import org.apache.directory.studio.schemaeditor.view.wrappers.ObjectClassWrapper; import org.eclipse.jface.viewers.IDecoration; import org.eclipse.jface.viewers.ILightweightLabelDecorator; import org.eclipse.jface.viewers.LabelProvider; /** * This class is the Schemas Editor Type Label Decorator. * It displays specific icons overlays for attribute types and object classes. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class SchemaEditorTypeLabelDecorator extends LabelProvider implements ILightweightLabelDecorator { /** * {@inheritDoc} */ public void decorate( Object element, IDecoration decoration ) { if ( element instanceof AttributeTypeWrapper ) { UsageEnum usage = ( ( AttributeTypeWrapper ) element ).getAttributeType().getUsage(); if ( usage == UsageEnum.USER_APPLICATIONS ) { decoration.addOverlay( Activator.getDefault().getImageDescriptor( PluginConstants.IMG_ATTRIBUTE_TYPE_OVERLAY_USER_APPLICATION ), IDecoration.BOTTOM_RIGHT ); } else if ( ( usage == UsageEnum.DIRECTORY_OPERATION ) || ( usage == UsageEnum.DISTRIBUTED_OPERATION ) || ( usage == UsageEnum.DSA_OPERATION ) ) { decoration.addOverlay( Activator.getDefault().getImageDescriptor( PluginConstants.IMG_ATTRIBUTE_TYPE_OVERLAY_OPERATION ), IDecoration.BOTTOM_RIGHT ); } } else if ( element instanceof ObjectClassWrapper ) { ObjectClassTypeEnum classType = ( ( ObjectClassWrapper ) element ).getObjectClass().getType(); if ( classType == ObjectClassTypeEnum.ABSTRACT ) { decoration.addOverlay( Activator.getDefault().getImageDescriptor( PluginConstants.IMG_OBJECT_CLASS_OVERLAY_ABSTRACT ), IDecoration.BOTTOM_RIGHT ); } else if ( classType == ObjectClassTypeEnum.STRUCTURAL ) { decoration.addOverlay( Activator.getDefault().getImageDescriptor( PluginConstants.IMG_OBJECT_CLASS_OVERLAY_STRUCTURAL ), IDecoration.BOTTOM_RIGHT ); } else if ( classType == ObjectClassTypeEnum.AUXILIARY ) { decoration.addOverlay( Activator.getDefault().getImageDescriptor( PluginConstants.IMG_OBJECT_CLASS_OVERLAY_AUXILIARY ), IDecoration.BOTTOM_RIGHT ); } } else if ( element instanceof AttributeType ) { UsageEnum usage = ( ( AttributeType ) element ).getUsage(); if ( usage == UsageEnum.USER_APPLICATIONS ) { decoration.addOverlay( Activator.getDefault().getImageDescriptor( PluginConstants.IMG_ATTRIBUTE_TYPE_OVERLAY_USER_APPLICATION ), IDecoration.BOTTOM_RIGHT ); } else if ( ( usage == UsageEnum.DIRECTORY_OPERATION ) || ( usage == UsageEnum.DISTRIBUTED_OPERATION ) || ( usage == UsageEnum.DSA_OPERATION ) ) { decoration.addOverlay( Activator.getDefault().getImageDescriptor( PluginConstants.IMG_ATTRIBUTE_TYPE_OVERLAY_OPERATION ), IDecoration.BOTTOM_RIGHT ); } } else if ( element instanceof ObjectClass ) { ObjectClassTypeEnum classType = ( ( ObjectClass ) element ).getType(); if ( classType == ObjectClassTypeEnum.ABSTRACT ) { decoration.addOverlay( Activator.getDefault().getImageDescriptor( PluginConstants.IMG_OBJECT_CLASS_OVERLAY_ABSTRACT ), IDecoration.BOTTOM_RIGHT ); } else if ( classType == ObjectClassTypeEnum.STRUCTURAL ) { decoration.addOverlay( Activator.getDefault().getImageDescriptor( PluginConstants.IMG_OBJECT_CLASS_OVERLAY_STRUCTURAL ), IDecoration.BOTTOM_RIGHT ); } else if ( classType == ObjectClassTypeEnum.AUXILIARY ) { decoration.addOverlay( Activator.getDefault().getImageDescriptor( PluginConstants.IMG_OBJECT_CLASS_OVERLAY_AUXILIARY ), IDecoration.BOTTOM_RIGHT ); } } } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/ViewUtils.java
plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/ViewUtils.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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.apache.directory.studio.schemaeditor.view; import java.util.List; import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.swt.SWT; import org.eclipse.swt.graphics.Color; import org.eclipse.ui.PlatformUI; /** * This Helper Class contains useful methods used to create the UI. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class ViewUtils { /** The Black Color */ public static final Color COLOR_BLACK = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell() .getDisplay().getSystemColor( SWT.COLOR_BLACK ); /** The Red Color */ public static final Color COLOR_RED = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell().getDisplay() .getSystemColor( SWT.COLOR_RED ); /** * Concatenates all aliases in a String format. Aliases are separated with a comma (',') * * @param aliases * the aliases to concatenate * @return * a String representing all aliases */ public static String concateAliases( List<String> aliases ) { StringBuffer sb = new StringBuffer(); if ( aliases.size() > 0 ) { sb.append( aliases.get( 0 ) ); for ( int i = 1; i < aliases.size(); i++ ) { sb.append( ", " ); //$NON-NLS-1$ sb.append( aliases.get( i ) ); } } return sb.toString(); } /** * Verifies that the given name is syntaxely correct according to the RFC 2252 * (Lightweight Directory Access Protocol (v3): Attribute Syntax Definitions). * * @param name * the name to test * @return * true if the name is correct, false if the name is not correct. */ public static boolean verifyName( String name ) { return name.matches( Messages.getString( "ViewUtils.AllowedCharacters" ) ); //$NON-NLS-1$ } /** * Displays an error message dialog with the given title and message. * * @param title the title of the window * @param message the message to display * @return <code>true</code> if the user presses the OK or Yes button, * <code>false</code> otherwise */ public static boolean displayErrorMessageDialog( String title, String message ) { return displayMessageDialog( MessageDialog.ERROR, title, message ); } /** * Displays a warning message dialog with the given title and message. * * @param title the title of the window * @param message the message to display * @return <code>true</code> if the user presses the OK or Yes button, * <code>false</code> otherwise */ public static boolean displayWarningMessageDialog( String title, String message ) { return displayMessageDialog( MessageDialog.WARNING, title, message ); } /** * Displays a information message dialog with the given title and message. * * @param title the title of the window * @param message the message to display * @return <code>true</code> if the user presses the OK or Yes button, * <code>false</code> otherwise */ public static boolean displayInformationMessageDialog( String title, String message ) { return displayMessageDialog( MessageDialog.INFORMATION, title, message ); } /** * Displays a Information Question message dialog with the given title and message. * * @param title the title of the window * @param message the message to display * @return <code>true</code> if the user presses the OK or Yes button, * <code>false</code> otherwise */ public static boolean displayQuestionMessageDialog( String title, String message ) { return displayMessageDialog( MessageDialog.QUESTION, title, message ); } /** * Displays a message dialog with the given style, title and message. * * @param kind the kind of dialog * @param title the title of the window * @param message the message to display * @return <code>true</code> if the user presses the OK or Yes button, * <code>false</code> otherwise */ private static boolean displayMessageDialog( int kind, String title, String message ) { return MessageDialog.open( kind, PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), title, message, SWT.NONE ); } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/Perspective.java
plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/Perspective.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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.apache.directory.studio.schemaeditor.view; import org.apache.directory.studio.schemaeditor.PluginConstants; import org.apache.directory.studio.schemaeditor.view.views.HierarchyView; import org.apache.directory.studio.schemaeditor.view.views.ProblemsView; import org.apache.directory.studio.schemaeditor.view.views.ProjectsView; import org.apache.directory.studio.schemaeditor.view.views.SchemaView; import org.apache.directory.studio.schemaeditor.view.views.SearchView; import org.apache.directory.studio.schemaeditor.view.wizards.NewAttributeTypeWizard; import org.apache.directory.studio.schemaeditor.view.wizards.NewObjectClassWizard; import org.apache.directory.studio.schemaeditor.view.wizards.NewProjectWizard; import org.apache.directory.studio.schemaeditor.view.wizards.NewSchemaWizard; import org.eclipse.ui.IFolderLayout; import org.eclipse.ui.IPageLayout; import org.eclipse.ui.IPerspectiveFactory; /** * This class represents the Schema Editor Perspective. * <p> * It is composed of two views, the Schema View and the Problems View, and the editor part. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class Perspective implements IPerspectiveFactory { /** The ID of the view */ public static final String ID = PluginConstants.PERSPECTIVE_SCHEMA_EDITOR_ID; /** The ID of the top left folder */ public static final String topLeftFolderId = PluginConstants.PERSPECTIVE_TOP_LEFT_FOLDER_ID; /** The ID of the bottom folder */ public static final String bottomFolderId = PluginConstants.PERSPECTIVE_BOTTOM_FOLDER_ID; /** * {@inheritDoc} */ public void createInitialLayout( IPageLayout layout ) { // Allowing the Editor Area layout.setEditorAreaVisible( true ); String editorAreaId = layout.getEditorArea(); // Creating top left folder IFolderLayout topLeftFolder = layout.createFolder( topLeftFolderId, IPageLayout.LEFT, 0.3f, editorAreaId ); // Creating bottom folder IFolderLayout bottomFolder = layout.createFolder( bottomFolderId, IPageLayout.BOTTOM, 0.7f, editorAreaId ); // Adding Views topLeftFolder.addView( SchemaView.ID ); topLeftFolder.addView( HierarchyView.ID ); layout.addStandaloneView( ProjectsView.ID, true, IPageLayout.BOTTOM, 0.7f, topLeftFolderId ); bottomFolder.addView( ProblemsView.ID ); bottomFolder.addView( SearchView.ID ); // Setting up non-closeable views layout.getViewLayout( SchemaView.ID ).setCloseable( false ); layout.getViewLayout( ProjectsView.ID ).setCloseable( false ); // Adding Perspective shortcuts layout.addPerspectiveShortcut( PluginConstants.PERSPECTIVE_LDAP_BROWSER_ID ); layout.addPerspectiveShortcut( Perspective.ID ); // Adding View shortcuts layout.addShowViewShortcut( SchemaView.ID ); layout.addShowViewShortcut( ProjectsView.ID ); layout.addShowViewShortcut( ProblemsView.ID ); layout.addShowViewShortcut( HierarchyView.ID ); layout.addShowViewShortcut( SearchView.ID ); // Adding New Wizard shortcuts layout.addNewWizardShortcut( NewProjectWizard.ID ); layout.addNewWizardShortcut( NewSchemaWizard.ID ); layout.addNewWizardShortcut( NewAttributeTypeWizard.ID ); layout.addNewWizardShortcut( NewObjectClassWizard.ID ); } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/SchemaEditorSchemaCheckerLabelDecorator.java
plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/SchemaEditorSchemaCheckerLabelDecorator.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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.apache.directory.studio.schemaeditor.view; import java.util.List; import org.apache.directory.api.ldap.model.schema.AttributeType; import org.apache.directory.api.ldap.model.schema.ObjectClass; import org.apache.directory.studio.schemaeditor.Activator; import org.apache.directory.studio.schemaeditor.PluginConstants; import org.apache.directory.studio.schemaeditor.model.Schema; import org.apache.directory.studio.schemaeditor.model.schemachecker.SchemaChecker; import org.apache.directory.studio.schemaeditor.view.wrappers.AttributeTypeWrapper; import org.apache.directory.studio.schemaeditor.view.wrappers.Folder; import org.apache.directory.studio.schemaeditor.view.wrappers.ObjectClassWrapper; import org.apache.directory.studio.schemaeditor.view.wrappers.SchemaWrapper; import org.apache.directory.studio.schemaeditor.view.wrappers.TreeNode; import org.eclipse.jface.viewers.IDecoration; import org.eclipse.jface.viewers.ILightweightLabelDecorator; import org.eclipse.jface.viewers.LabelProvider; /** * This class is the Schemas Editor Schema Checker Label Decorator. * It displays specific icons overlays for attribute types and object classes * based on their state in the schema checker. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class SchemaEditorSchemaCheckerLabelDecorator extends LabelProvider implements ILightweightLabelDecorator { /** * {@inheritDoc} */ public void decorate( Object element, IDecoration decoration ) { SchemaChecker schemaChecker = Activator.getDefault().getSchemaChecker(); ElementState state = ElementState.NONE; if ( element instanceof AttributeTypeWrapper ) { AttributeType at = ( ( AttributeTypeWrapper ) element ).getAttributeType(); if ( schemaChecker.hasErrors( at ) ) { decorateState( ElementState.ERROR, decoration ); return; } if ( schemaChecker.hasWarnings( at ) ) { state = ElementState.WARNING; } } else if ( element instanceof ObjectClassWrapper ) { ObjectClass oc = ( ( ObjectClassWrapper ) element ).getObjectClass(); if ( schemaChecker.hasErrors( oc ) ) { decorateState( ElementState.ERROR, decoration ); return; } if ( schemaChecker.hasWarnings( oc ) ) { state = ElementState.WARNING; } } else if ( element instanceof SchemaWrapper ) { Schema schema = ( ( SchemaWrapper ) element ).getSchema(); for ( AttributeType at : schema.getAttributeTypes() ) { if ( schemaChecker.hasErrors( at ) ) { decorateState( ElementState.ERROR, decoration ); return; } if ( schemaChecker.hasWarnings( at ) ) { state = ElementState.WARNING; } } for ( ObjectClass oc : schema.getObjectClasses() ) { if ( schemaChecker.hasErrors( oc ) ) { decorateState( ElementState.ERROR, decoration ); return; } if ( schemaChecker.hasWarnings( oc ) ) { state = ElementState.WARNING; } } } else if ( element instanceof Folder ) { Folder folder = ( Folder ) element; if ( childrenHasErrors( folder.getChildren(), schemaChecker ) ) { decorateState( ElementState.ERROR, decoration ); return; } if ( childrenHasWarnings( folder.getChildren(), schemaChecker ) ) { state = ElementState.WARNING; } } decorateState( state, decoration ); } /** * Decorates the element from the value of its state. * * @param state * the state * @param decoration * the decoration */ private void decorateState( ElementState state, IDecoration decoration ) { switch ( state ) { case WARNING: decoration.addOverlay( Activator.getDefault().getImageDescriptor( PluginConstants.IMG_OVERLAY_WARNING ), IDecoration.BOTTOM_LEFT ); break; case ERROR: decoration.addOverlay( Activator.getDefault().getImageDescriptor( PluginConstants.IMG_OVERLAY_ERROR ), IDecoration.BOTTOM_LEFT ); break; default: break; } } /** * Verifies if the given children list contains elements that have warnings. * * @param children * the children list * @param schemaChecker * the schemaChecker * @return * true if the given children list contains elements that have warnings */ public boolean childrenHasWarnings( List<TreeNode> children, SchemaChecker schemaChecker ) { if ( children != null ) { for ( TreeNode child : children ) { if ( child instanceof AttributeTypeWrapper ) { AttributeType at = ( ( AttributeTypeWrapper ) child ).getAttributeType(); if ( schemaChecker.hasWarnings( at ) ) { return true; } else { if ( childrenHasWarnings( child.getChildren(), schemaChecker ) ) { return true; } } } else if ( child instanceof ObjectClassWrapper ) { ObjectClass oc = ( ( ObjectClassWrapper ) child ).getObjectClass(); if ( schemaChecker.hasWarnings( oc ) ) { return true; } else { if ( childrenHasWarnings( child.getChildren(), schemaChecker ) ) { return true; } } } } } return false; } /** * Verifies if the given children list contains elements that have warnings. * * @param children * the children list * @param schemaChecker * the schemaChecker * @return * true if the given children list contains elements that have warnings */ public boolean childrenHasErrors( List<TreeNode> children, SchemaChecker schemaChecker ) { if ( children != null ) { for ( TreeNode child : children ) { if ( child instanceof AttributeTypeWrapper ) { AttributeType at = ( ( AttributeTypeWrapper ) child ).getAttributeType(); if ( schemaChecker.hasErrors( at ) ) { return true; } else { if ( childrenHasErrors( child.getChildren(), schemaChecker ) ) { return true; } } } else if ( child instanceof ObjectClassWrapper ) { ObjectClass oc = ( ( ObjectClassWrapper ) child ).getObjectClass(); if ( schemaChecker.hasErrors( oc ) ) { return true; } else { if ( childrenHasErrors( child.getChildren(), schemaChecker ) ) { return true; } } } } } return false; } /** * This enum defines the state of an element. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ private enum ElementState { NONE, WARNING, ERROR; } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/views/SearchView.java
plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/views/SearchView.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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.apache.directory.studio.schemaeditor.view.views; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.regex.Pattern; import org.apache.directory.api.ldap.model.schema.AttributeType; import org.apache.directory.api.ldap.model.schema.ObjectClass; import org.apache.directory.api.ldap.model.schema.SchemaObject; import org.apache.directory.studio.schemaeditor.Activator; import org.apache.directory.studio.schemaeditor.PluginConstants; import org.apache.directory.studio.schemaeditor.PluginUtils; import org.apache.directory.studio.schemaeditor.controller.SchemaHandler; import org.apache.directory.studio.schemaeditor.controller.SearchViewController; import org.apache.directory.studio.schemaeditor.view.ViewUtils; import org.apache.directory.studio.schemaeditor.view.editors.attributetype.AttributeTypeEditor; import org.apache.directory.studio.schemaeditor.view.editors.attributetype.AttributeTypeEditorInput; import org.apache.directory.studio.schemaeditor.view.editors.objectclass.ObjectClassEditor; import org.apache.directory.studio.schemaeditor.view.editors.objectclass.ObjectClassEditorInput; import org.apache.directory.studio.schemaeditor.view.search.SearchPage; import org.apache.directory.studio.schemaeditor.view.search.SearchPage.SearchInEnum; import org.eclipse.jface.action.Action; import org.eclipse.jface.dialogs.IDialogSettings; import org.eclipse.jface.viewers.DecoratingLabelProvider; import org.eclipse.jface.viewers.DoubleClickEvent; import org.eclipse.jface.viewers.IDoubleClickListener; import org.eclipse.jface.viewers.StructuredSelection; import org.eclipse.jface.viewers.TableViewer; import org.eclipse.swt.SWT; import org.eclipse.swt.events.KeyAdapter; import org.eclipse.swt.events.KeyEvent; import org.eclipse.swt.events.ModifyEvent; import org.eclipse.swt.events.ModifyListener; import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.graphics.Point; import org.eclipse.swt.graphics.Rectangle; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Menu; import org.eclipse.swt.widgets.MenuItem; import org.eclipse.swt.widgets.Table; import org.eclipse.swt.widgets.Text; import org.eclipse.swt.widgets.ToolBar; import org.eclipse.swt.widgets.ToolItem; import org.eclipse.ui.IEditorInput; import org.eclipse.ui.PartInitException; import org.eclipse.ui.PlatformUI; import org.eclipse.ui.part.ViewPart; /** * This class represents the Search View. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class SearchView extends ViewPart { /** The view's ID */ public static final String ID = PluginConstants.VIEW_SEARCH_VIEW_ID; /** The current Search String */ private String searchString; // UI fields private Text searchField; private Button searchButton; private Label searchResultsLabel; private Table resultsTable; private TableViewer resultsTableViewer; private Composite searchFieldComposite; private Composite searchFieldInnerComposite; private Label separatorLabel; /** The parent composite */ private Composite parent; /** * {@inheritDoc} */ public void createPartControl( Composite parent ) { // Help Context for Dynamic Help PlatformUI.getWorkbench().getHelpSystem().setHelp( parent, PluginConstants.PLUGIN_ID + "." + "search_view" ); //$NON-NLS-1$ //$NON-NLS-2$ this.parent = parent; GridLayout gridLayout = new GridLayout(); gridLayout.horizontalSpacing = 0; gridLayout.marginBottom = 0; gridLayout.marginHeight = 0; gridLayout.marginLeft = 0; gridLayout.marginRight = 0; gridLayout.marginTop = 0; gridLayout.marginWidth = 0; gridLayout.verticalSpacing = 0; parent.setLayout( gridLayout ); // Search Field searchFieldComposite = new Composite( parent, SWT.NONE ); gridLayout = new GridLayout(); gridLayout.horizontalSpacing = 0; gridLayout.marginBottom = 0; gridLayout.marginHeight = 0; gridLayout.marginLeft = 0; gridLayout.marginRight = 0; gridLayout.marginTop = 0; gridLayout.marginWidth = 0; gridLayout.verticalSpacing = 0; searchFieldComposite.setLayout( gridLayout ); searchFieldComposite.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) ); // This searchFieldCompositeSeparator is used to display correctly the searchFieldComposite, // since an empty composite does not display well. Label searchFieldCompositeSeparator = new Label( searchFieldComposite, SWT.SEPARATOR | SWT.HORIZONTAL ); GridData gridData = new GridData( SWT.FILL, SWT.NONE, true, false ); gridData.heightHint = 1; searchFieldCompositeSeparator.setLayoutData( gridData ); searchFieldCompositeSeparator.setVisible( false ); // Search Results Label searchResultsLabel = new Label( parent, SWT.NONE ); searchResultsLabel.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) ); // Separator Label Label separatorLabel2 = new Label( parent, SWT.SEPARATOR | SWT.HORIZONTAL ); separatorLabel2.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) ); // Create the table createTableViewer(); setSearchResultsLabel( null, 0 ); new SearchViewController( this ); } /** * Create the Search Field Sections. */ private void createSearchField() { // Search Inner Composite searchFieldInnerComposite = new Composite( searchFieldComposite, SWT.NONE ); GridLayout searchFieldInnerCompositeGridLayout = new GridLayout( 4, false ); searchFieldInnerCompositeGridLayout.horizontalSpacing = 1; searchFieldInnerCompositeGridLayout.verticalSpacing = 1; searchFieldInnerCompositeGridLayout.marginHeight = 1; searchFieldInnerCompositeGridLayout.marginWidth = 2; searchFieldInnerComposite.setLayout( searchFieldInnerCompositeGridLayout ); searchFieldInnerComposite.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) ); // Search Label Label searchFieldLabel = new Label( searchFieldInnerComposite, SWT.NONE ); searchFieldLabel.setText( Messages.getString( "SearchView.SearchColon" ) ); //$NON-NLS-1$ searchFieldLabel.setLayoutData( new GridData( SWT.NONE, SWT.CENTER, false, false ) ); // Search Text Field searchField = new Text( searchFieldInnerComposite, SWT.BORDER | SWT.SEARCH | SWT.CANCEL ); if ( searchString != null ) { searchField.setText( searchString ); } searchField.setLayoutData( new GridData( SWT.FILL, SWT.CENTER, true, false ) ); searchField.addModifyListener( new ModifyListener() { public void modifyText( ModifyEvent e ) { validateSearchField(); } } ); searchField.addKeyListener( new KeyAdapter() { public void keyReleased( KeyEvent e ) { if ( e.keyCode == SWT.ARROW_DOWN ) { resultsTable.setFocus(); } else if ( ( e.keyCode == Action.findKeyCode( "RETURN" ) ) || ( e.keyCode == SWT.KEYPAD_CR ) ) //$NON-NLS-1$ { search(); } } } ); // Search Toolbar final ToolBar searchToolBar = new ToolBar( searchFieldInnerComposite, SWT.HORIZONTAL | SWT.FLAT ); // Creating the Search In ToolItem final ToolItem searchInToolItem = new ToolItem( searchToolBar, SWT.DROP_DOWN ); searchInToolItem.setText( Messages.getString( "SearchView.SearchIn" ) ); //$NON-NLS-1$ // Adding the action to display the Menu when the item is clicked searchInToolItem.addSelectionListener( new SelectionAdapter() { public void widgetSelected( SelectionEvent event ) { Rectangle rect = searchInToolItem.getBounds(); Point pt = new Point( rect.x, rect.y + rect.height ); pt = searchToolBar.toDisplay( pt ); Menu menu = createSearchInMenu(); menu.setLocation( pt.x, pt.y ); menu.setVisible( true ); } } ); new ToolItem( searchToolBar, SWT.SEPARATOR ); final ToolItem scopeToolItem = new ToolItem( searchToolBar, SWT.DROP_DOWN ); scopeToolItem.setText( Messages.getString( "SearchView.Scope" ) ); //$NON-NLS-1$ // Adding the action to display the Menu when the item is clicked scopeToolItem.addSelectionListener( new SelectionAdapter() { public void widgetSelected( SelectionEvent event ) { Rectangle rect = scopeToolItem.getBounds(); Point pt = new Point( rect.x, rect.y + rect.height ); pt = searchToolBar.toDisplay( pt ); Menu menu = createScopeMenu(); menu.setLocation( pt.x, pt.y ); menu.setVisible( true ); } } ); searchToolBar.setLayoutData( new GridData( SWT.NONE, SWT.CENTER, false, false ) ); // Search Button searchButton = new Button( searchFieldInnerComposite, SWT.PUSH | SWT.DOWN ); searchButton.setEnabled( false ); searchButton.setImage( Activator.getDefault().getImage( PluginConstants.IMG_SEARCH ) ); searchButton.setToolTipText( Messages.getString( "SearchView.Search" ) ); //$NON-NLS-1$ searchButton.addSelectionListener( new SelectionAdapter() { public void widgetSelected( SelectionEvent e ) { search(); } } ); searchButton.setLayoutData( new GridData( SWT.NONE, SWT.CENTER, false, false ) ); // Separator Label separatorLabel = new Label( searchFieldComposite, SWT.SEPARATOR | SWT.HORIZONTAL ); separatorLabel.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) ); } /** * Creates the Search In Menu * * @return * the Search In menu */ public Menu createSearchInMenu() { final IDialogSettings settings = Activator.getDefault().getDialogSettings(); // Creating the associated Menu Menu searchInMenu = new Menu( PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), SWT.POP_UP ); // Filling the menu // Aliases final MenuItem aliasesMenuItem = new MenuItem( searchInMenu, SWT.CHECK ); aliasesMenuItem.setText( Messages.getString( "SearchView.Aliases" ) ); //$NON-NLS-1$ aliasesMenuItem.addSelectionListener( new SelectionAdapter() { public void widgetSelected( SelectionEvent e ) { settings.put( PluginConstants.PREFS_SEARCH_PAGE_SEARCH_IN_ALIASES, aliasesMenuItem.getSelection() ); } } ); // OID final MenuItem oidMenuItem = new MenuItem( searchInMenu, SWT.CHECK ); oidMenuItem.setText( Messages.getString( "SearchView.OID" ) ); //$NON-NLS-1$ oidMenuItem.addSelectionListener( new SelectionAdapter() { public void widgetSelected( SelectionEvent e ) { settings.put( PluginConstants.PREFS_SEARCH_PAGE_SEARCH_IN_OID, oidMenuItem.getSelection() ); } } ); // Description final MenuItem descriptionMenuItem = new MenuItem( searchInMenu, SWT.CHECK ); descriptionMenuItem.setText( Messages.getString( "SearchView.Description" ) ); //$NON-NLS-1$ descriptionMenuItem.addSelectionListener( new SelectionAdapter() { public void widgetSelected( SelectionEvent e ) { settings.put( PluginConstants.PREFS_SEARCH_PAGE_SEARCH_IN_DESCRIPTION, descriptionMenuItem .getSelection() ); } } ); // Separator new MenuItem( searchInMenu, SWT.SEPARATOR ); // Superior final MenuItem superiorMenuItem = new MenuItem( searchInMenu, SWT.CHECK ); superiorMenuItem.setText( Messages.getString( "SearchView.Superior" ) ); //$NON-NLS-1$ superiorMenuItem.addSelectionListener( new SelectionAdapter() { public void widgetSelected( SelectionEvent e ) { settings.put( PluginConstants.PREFS_SEARCH_PAGE_SEARCH_IN_SUPERIOR, superiorMenuItem.getSelection() ); } } ); // Syntax final MenuItem syntaxMenuItem = new MenuItem( searchInMenu, SWT.CHECK ); syntaxMenuItem.setText( Messages.getString( "SearchView.Syntax" ) ); //$NON-NLS-1$ syntaxMenuItem.addSelectionListener( new SelectionAdapter() { public void widgetSelected( SelectionEvent e ) { settings.put( PluginConstants.PREFS_SEARCH_PAGE_SEARCH_IN_SYNTAX, syntaxMenuItem.getSelection() ); } } ); // Matching Rules final MenuItem matchingRulesMenuItem = new MenuItem( searchInMenu, SWT.CHECK ); matchingRulesMenuItem.setText( Messages.getString( "SearchView.MatchingRules" ) ); //$NON-NLS-1$ matchingRulesMenuItem.addSelectionListener( new SelectionAdapter() { public void widgetSelected( SelectionEvent e ) { settings.put( PluginConstants.PREFS_SEARCH_PAGE_SEARCH_IN_MATCHING_RULES, matchingRulesMenuItem .getSelection() ); } } ); // Separator new MenuItem( searchInMenu, SWT.SEPARATOR ); // Superiors final MenuItem superiorsMenuItem = new MenuItem( searchInMenu, SWT.CHECK ); superiorsMenuItem.setText( Messages.getString( "SearchView.Superiors" ) ); //$NON-NLS-1$ superiorsMenuItem.addSelectionListener( new SelectionAdapter() { public void widgetSelected( SelectionEvent e ) { settings.put( PluginConstants.PREFS_SEARCH_PAGE_SEARCH_IN_SUPERIORS, superiorsMenuItem.getSelection() ); } } ); // Mandatory Attributes final MenuItem mandatoryAttributesMenuItem = new MenuItem( searchInMenu, SWT.CHECK ); mandatoryAttributesMenuItem.setText( Messages.getString( "SearchView.MandatoryAttributes" ) ); //$NON-NLS-1$ mandatoryAttributesMenuItem.addSelectionListener( new SelectionAdapter() { public void widgetSelected( SelectionEvent e ) { settings.put( PluginConstants.PREFS_SEARCH_PAGE_SEARCH_IN_MANDATORY_ATTRIBUTES, mandatoryAttributesMenuItem.getSelection() ); } } ); // Optional Attributes final MenuItem optionalAttributesMenuItem = new MenuItem( searchInMenu, SWT.CHECK ); optionalAttributesMenuItem.setText( Messages.getString( "SearchView.OptionalAttributes" ) ); //$NON-NLS-1$ optionalAttributesMenuItem.addSelectionListener( new SelectionAdapter() { public void widgetSelected( SelectionEvent e ) { settings.put( PluginConstants.PREFS_SEARCH_PAGE_SEARCH_IN_OPTIONAL_ATTRIBUTES, optionalAttributesMenuItem.getSelection() ); } } ); if ( settings.get( PluginConstants.PREFS_SEARCH_PAGE_SEARCH_IN_ALIASES ) == null ) { aliasesMenuItem.setSelection( true ); } else { aliasesMenuItem.setSelection( settings.getBoolean( PluginConstants.PREFS_SEARCH_PAGE_SEARCH_IN_ALIASES ) ); } if ( settings.get( PluginConstants.PREFS_SEARCH_PAGE_SEARCH_IN_OID ) == null ) { oidMenuItem.setSelection( true ); } else { oidMenuItem.setSelection( settings.getBoolean( PluginConstants.PREFS_SEARCH_PAGE_SEARCH_IN_OID ) ); } if ( settings.get( PluginConstants.PREFS_SEARCH_PAGE_SEARCH_IN_DESCRIPTION ) == null ) { descriptionMenuItem.setSelection( true ); } else { descriptionMenuItem.setSelection( settings .getBoolean( PluginConstants.PREFS_SEARCH_PAGE_SEARCH_IN_DESCRIPTION ) ); } superiorMenuItem.setSelection( settings.getBoolean( PluginConstants.PREFS_SEARCH_PAGE_SEARCH_IN_SUPERIOR ) ); syntaxMenuItem.setSelection( settings.getBoolean( PluginConstants.PREFS_SEARCH_PAGE_SEARCH_IN_SYNTAX ) ); matchingRulesMenuItem.setSelection( settings .getBoolean( PluginConstants.PREFS_SEARCH_PAGE_SEARCH_IN_MATCHING_RULES ) ); superiorsMenuItem.setSelection( settings.getBoolean( PluginConstants.PREFS_SEARCH_PAGE_SEARCH_IN_SUPERIORS ) ); mandatoryAttributesMenuItem.setSelection( settings .getBoolean( PluginConstants.PREFS_SEARCH_PAGE_SEARCH_IN_MANDATORY_ATTRIBUTES ) ); optionalAttributesMenuItem.setSelection( settings .getBoolean( PluginConstants.PREFS_SEARCH_PAGE_SEARCH_IN_OPTIONAL_ATTRIBUTES ) ); return searchInMenu; } /** * Creates the Scope Menu * * @return * the Scope menu */ public Menu createScopeMenu() { final IDialogSettings settings = Activator.getDefault().getDialogSettings(); // Creating the associated Menu Menu scopeMenu = new Menu( PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), SWT.POP_UP ); // Filling the menu // Attribute Types And Object Classes final MenuItem attributeTypesAndObjectClassesMenuItem = new MenuItem( scopeMenu, SWT.RADIO ); attributeTypesAndObjectClassesMenuItem.setText( Messages.getString( "SearchView.TypesAndClasses" ) ); //$NON-NLS-1$ attributeTypesAndObjectClassesMenuItem.addSelectionListener( new SelectionAdapter() { public void widgetSelected( SelectionEvent e ) { settings.put( PluginConstants.PREFS_SEARCH_PAGE_SCOPE, PluginConstants.PREFS_SEARCH_PAGE_SCOPE_AT_AND_OC ); } } ); // Attributes Type Only final MenuItem attributesTypesOnlyMenuItem = new MenuItem( scopeMenu, SWT.RADIO ); attributesTypesOnlyMenuItem.setText( Messages.getString( "SearchView.TypesOnly" ) ); //$NON-NLS-1$ attributesTypesOnlyMenuItem.addSelectionListener( new SelectionAdapter() { public void widgetSelected( SelectionEvent e ) { settings.put( PluginConstants.PREFS_SEARCH_PAGE_SCOPE, PluginConstants.PREFS_SEARCH_PAGE_SCOPE_AT_ONLY ); } } ); // Object Classes Only final MenuItem objectClassesMenuItem = new MenuItem( scopeMenu, SWT.RADIO ); objectClassesMenuItem.setText( Messages.getString( "SearchView.ClassesOnly" ) ); //$NON-NLS-1$ objectClassesMenuItem.addSelectionListener( new SelectionAdapter() { public void widgetSelected( SelectionEvent e ) { settings.put( PluginConstants.PREFS_SEARCH_PAGE_SCOPE, PluginConstants.PREFS_SEARCH_PAGE_SCOPE_OC_ONLY ); } } ); if ( settings.get( PluginConstants.PREFS_SEARCH_PAGE_SCOPE ) == null ) { attributeTypesAndObjectClassesMenuItem.setSelection( true ); } else { switch ( settings.getInt( PluginConstants.PREFS_SEARCH_PAGE_SCOPE ) ) { case PluginConstants.PREFS_SEARCH_PAGE_SCOPE_AT_AND_OC: attributeTypesAndObjectClassesMenuItem.setSelection( true ); break; case PluginConstants.PREFS_SEARCH_PAGE_SCOPE_AT_ONLY: attributesTypesOnlyMenuItem.setSelection( true ); break; case PluginConstants.PREFS_SEARCH_PAGE_SCOPE_OC_ONLY: objectClassesMenuItem.setSelection( true ); break; } } return scopeMenu; } /** * Creates the TableViewer. */ private void createTableViewer() { // Creating the TableViewer resultsTable = new Table( parent, SWT.SINGLE | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.HIDE_SELECTION ); GridData gridData = new GridData( SWT.FILL, SWT.FILL, true, true ); resultsTable.setLayoutData( gridData ); resultsTable.setLinesVisible( true ); // Creating the TableViewer resultsTableViewer = new TableViewer( resultsTable ); resultsTableViewer.setLabelProvider( new DecoratingLabelProvider( new SearchViewLabelProvider(), Activator .getDefault().getWorkbench().getDecoratorManager().getLabelDecorator() ) ); resultsTableViewer.setContentProvider( new SearchViewContentProvider() ); // Adding listeners resultsTable.addKeyListener( new KeyAdapter() { public void keyPressed( KeyEvent e ) { if ( ( e.keyCode == Action.findKeyCode( "RETURN" ) ) || ( e.keyCode == SWT.KEYPAD_CR ) ) // return key //$NON-NLS-1$ { openEditor(); } } } ); resultsTableViewer.addDoubleClickListener( new IDoubleClickListener() { public void doubleClick( DoubleClickEvent event ) { openEditor(); } } ); } /** * Open the editor associated with the current selection in the table. */ private void openEditor() { if ( Activator.getDefault().getSchemaHandler() != null ) { StructuredSelection selection = ( StructuredSelection ) resultsTableViewer.getSelection(); if ( !selection.isEmpty() ) { Object item = selection.getFirstElement(); IEditorInput input = null; String editorId = null; // Here is the double clicked item if ( item instanceof AttributeType ) { input = new AttributeTypeEditorInput( ( AttributeType ) item ); editorId = AttributeTypeEditor.ID; } else if ( item instanceof ObjectClass ) { input = new ObjectClassEditorInput( ( ObjectClass ) item ); editorId = ObjectClassEditor.ID; } // Let's open the editor if ( input != null ) { try { PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().openEditor( input, editorId ); } catch ( PartInitException exception ) { PluginUtils.logError( Messages.getString( "SearchView.ErrorOpeningEditor" ), exception ); //$NON-NLS-1$ ViewUtils .displayErrorMessageDialog( Messages.getString( "SearchView.Error" ), Messages.getString( "SearchView.ErrorOpeningEditor" ) ); //$NON-NLS-1$ //$NON-NLS-2$ } } } } } /** * {@inheritDoc} */ public void setFocus() { if ( searchField != null && !searchField.isDisposed() ) { searchField.setFocus(); } else { resultsTable.setFocus(); } } /** * Shows the Search Field Section. */ public void showSearchFieldSection() { createSearchField(); parent.layout( true, true ); searchField.setFocus(); validateSearchField(); } /** * Hides the Search Field Section. */ public void hideSearchFieldSection() { if ( searchFieldInnerComposite != null ) { searchFieldInnerComposite.dispose(); searchFieldInnerComposite = null; } if ( separatorLabel != null ) { separatorLabel.dispose(); separatorLabel = null; } parent.layout( true, true ); resultsTable.setFocus(); } private void validateSearchField() { searchButton.setEnabled( searchField.getText().length() > 0 ); } /** * Sets the Search Input. * * @param searchString * the search String * @param searchIn * the search In * @param scope * the scope */ public void setSearchInput( String searchString, SearchInEnum[] searchIn, int scope ) { this.searchString = searchString; // Saving search String and Search Scope to dialog settings SearchPage.addSearchStringHistory( searchString ); SearchPage.saveSearchScope( Arrays.asList( searchIn ) ); if ( ( searchField != null ) && ( !searchField.isDisposed() ) ) { searchField.setText( searchString ); validateSearchField(); } List<SchemaObject> results = search( searchString, searchIn, scope ); setSearchResultsLabel( searchString, results.size() ); resultsTableViewer.setInput( results ); } /** * Searches the objects corresponding to the search parameters. * * @param searchString * the search String * @param searchIn * the search In * @param scope * the scope */ private List<SchemaObject> search( String searchString, SearchInEnum[] searchIn, int scope ) { List<SchemaObject> searchResults = new ArrayList<SchemaObject>(); if ( searchString != null ) { String computedSearchString = searchString.replaceAll( "\\*", "[\\\\S]*" ); //$NON-NLS-1$ //$NON-NLS-2$ computedSearchString = computedSearchString.replaceAll( "\\?", "[\\\\S]" ); //$NON-NLS-1$ //$NON-NLS-2$ Pattern pattern = Pattern.compile( computedSearchString, Pattern.CASE_INSENSITIVE ); SchemaHandler schemaHandler = Activator.getDefault().getSchemaHandler(); if ( schemaHandler != null ) { List<SearchInEnum> searchScope = new ArrayList<SearchInEnum>( Arrays.asList( searchIn ) ); if ( ( scope == PluginConstants.PREFS_SEARCH_PAGE_SCOPE_AT_AND_OC ) || ( scope == PluginConstants.PREFS_SEARCH_PAGE_SCOPE_AT_ONLY ) ) { // Looping on attribute types List<AttributeType> attributeTypes = schemaHandler.getAttributeTypes(); for ( AttributeType at : attributeTypes ) { // Aliases if ( searchScope.contains( SearchInEnum.ALIASES ) ) { if ( checkList( pattern, at.getNames() ) ) { searchResults.add( at ); continue; } } // OID if ( searchScope.contains( SearchInEnum.OID ) ) { if ( checkString( pattern, at.getOid() ) ) { searchResults.add( at ); continue; } } // Description if ( searchScope.contains( SearchInEnum.DESCRIPTION ) ) { if ( checkString( pattern, at.getDescription() ) ) { searchResults.add( at ); continue; } } // Superior if ( searchScope.contains( SearchInEnum.SUPERIOR ) ) { if ( checkString( pattern, at.getSuperiorOid() ) ) { searchResults.add( at ); continue; } } // Syntax if ( searchScope.contains( SearchInEnum.SYNTAX ) ) { if ( checkString( pattern, at.getSyntaxOid() ) ) { searchResults.add( at ); continue; } } // Matching Rules if ( searchScope.contains( SearchInEnum.MATCHING_RULES ) ) { // Equality if ( checkString( pattern, at.getEqualityOid() ) ) { searchResults.add( at ); continue; } // Ordering if ( checkString( pattern, at.getOrderingOid() ) ) { searchResults.add( at ); continue; } // Substring if ( checkString( pattern, at.getSubstringOid() ) ) { searchResults.add( at ); continue; } } } } if ( ( scope == PluginConstants.PREFS_SEARCH_PAGE_SCOPE_AT_AND_OC ) || ( scope == PluginConstants.PREFS_SEARCH_PAGE_SCOPE_OC_ONLY ) ) { // Looping on object classes List<ObjectClass> objectClasses = schemaHandler.getObjectClasses(); for ( ObjectClass oc : objectClasses ) { // Aliases if ( searchScope.contains( SearchInEnum.ALIASES ) ) { if ( checkList( pattern, oc.getNames() ) ) { searchResults.add( oc ); continue; } } // OID if ( searchScope.contains( SearchInEnum.OID ) ) { if ( checkString( pattern, oc.getOid() ) ) { searchResults.add( oc ); continue; } } // Description if ( searchScope.contains( SearchInEnum.DESCRIPTION ) ) { if ( checkString( pattern, oc.getDescription() ) ) { searchResults.add( oc ); continue; } } // Superiors
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
true
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/views/ProblemsView.java
plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/views/ProblemsView.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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.apache.directory.studio.schemaeditor.view.views; import org.apache.directory.studio.schemaeditor.Activator; import org.apache.directory.studio.schemaeditor.PluginConstants; import org.apache.directory.studio.schemaeditor.controller.ProblemsViewController; import org.apache.directory.studio.schemaeditor.model.schemachecker.SchemaChecker; import org.apache.directory.studio.schemaeditor.view.wrappers.ProblemsViewRoot; import org.eclipse.jface.viewers.TreeViewer; import org.eclipse.swt.SWT; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Tree; import org.eclipse.swt.widgets.TreeColumn; import org.eclipse.ui.PlatformUI; import org.eclipse.ui.part.ViewPart; /** * This class represents the SchemaView. * It is used to display the Schema and its elements (Schemas, AttributeTypes * and ObjectClasses). * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class ProblemsView extends ViewPart { /** The ID of the View */ public static final String ID = PluginConstants.VIEW_PROBLEMS_VIEW_ID; /** The viewer */ private TreeViewer treeViewer; /** The content provider of the viewer */ private ProblemsViewContentProvider contentProvider; /** The overview label */ private Label overviewLabel; /** The SchemaChecker */ private SchemaChecker schemaChecker; /** The Controller */ private ProblemsViewController controller; /** * {@inheritDoc} */ public void createPartControl( Composite parent ) { // Help Context for Dynamic Help PlatformUI.getWorkbench().getHelpSystem().setHelp( parent, PluginConstants.PLUGIN_ID + "." + "problems_view" ); //$NON-NLS-1$ //$NON-NLS-2$ GridLayout gridLayout = new GridLayout(); gridLayout.horizontalSpacing = 0; gridLayout.marginBottom = 0; gridLayout.marginHeight = 0; gridLayout.marginLeft = 0; gridLayout.marginRight = 0; gridLayout.marginTop = 0; gridLayout.marginWidth = 0; gridLayout.verticalSpacing = 0; parent.setLayout( gridLayout ); // Overview Label overviewLabel = new Label( parent, SWT.NULL ); setErrorsAndWarningsCount( 0, 0 ); overviewLabel.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) ); // Separator Label Label separatorLabel = new Label( parent, SWT.SEPARATOR | SWT.HORIZONTAL ); separatorLabel.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) ); // Viewer initViewer( parent ); // Adding the controller controller = new ProblemsViewController( this ); } /** * Initializes the Viewer */ private void initViewer( Composite parent ) { treeViewer = new TreeViewer( parent, SWT.FULL_SELECTION | SWT.H_SCROLL | SWT.V_SCROLL ); Tree tree = treeViewer.getTree(); tree.setLayoutData( new GridData( SWT.FILL, SWT.FILL, true, true ) ); tree.setHeaderVisible( true ); tree.setLinesVisible( true ); TreeColumn descriptionColumn = new TreeColumn( tree, SWT.LEFT ); descriptionColumn.setText( Messages.getString( "ProblemsView.Description" ) ); //$NON-NLS-1$ descriptionColumn.setWidth( 500 ); TreeColumn resourceColumn = new TreeColumn( tree, SWT.LEFT ); resourceColumn.setText( Messages.getString( "ProblemsView.Resource" ) ); //$NON-NLS-1$ resourceColumn.setWidth( 100 ); contentProvider = new ProblemsViewContentProvider(); treeViewer.setContentProvider( contentProvider ); treeViewer.setLabelProvider( new ProblemsViewLabelProvider() ); } /** * {@inheritDoc} */ public void setFocus() { treeViewer.getTree().setFocus(); } /** * Gets the TreeViewer. * * @return * the TreeViewer */ public TreeViewer getViewer() { return treeViewer; } /** * Reloads the Viewer */ public void reloadViewer() { treeViewer.setInput( new ProblemsViewRoot() ); treeViewer.expandAll(); schemaChecker = Activator.getDefault().getSchemaChecker(); if ( schemaChecker != null ) { setErrorsAndWarningsCount( schemaChecker.getErrors().size(), schemaChecker.getWarnings().size() ); } else { setErrorsAndWarningsCount( 0, 0 ); } } /** * Refresh the overview label with the number of errors and warnings. * * @param errors * the number of errors * @param warnings * the number of warnings */ public void setErrorsAndWarningsCount( int errors, int warnings ) { StringBuffer sb = new StringBuffer(); sb.append( errors ); sb.append( " " ); //$NON-NLS-1$ if ( errors > 1 ) { sb.append( Messages.getString( "ProblemsView.Errors" ) ); //$NON-NLS-1$ } else { sb.append( Messages.getString( "ProblemsView.Error" ) ); //$NON-NLS-1$ } sb.append( ", " ); //$NON-NLS-1$ sb.append( warnings ); sb.append( " " ); //$NON-NLS-1$ if ( warnings > 1 ) { sb.append( Messages.getString( "ProblemsView.Warnings" ) ); //$NON-NLS-1$ } else { sb.append( Messages.getString( "ProblemsView.Warning" ) ); //$NON-NLS-1$ } overviewLabel.setText( sb.toString() ); } /** * {@inheritDoc} */ public void dispose() { controller.dispose(); } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/views/HierarchyView.java
plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/views/HierarchyView.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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.apache.directory.studio.schemaeditor.view.views; import java.util.List; import org.apache.directory.api.ldap.model.schema.AttributeType; import org.apache.directory.api.ldap.model.schema.ObjectClass; import org.apache.directory.api.ldap.model.schema.SchemaObject; import org.apache.directory.studio.schemaeditor.Activator; import org.apache.directory.studio.schemaeditor.PluginConstants; import org.apache.directory.studio.schemaeditor.controller.HierarchyViewController; import org.apache.directory.studio.schemaeditor.view.ViewUtils; import org.eclipse.jface.viewers.DecoratingLabelProvider; import org.eclipse.jface.viewers.TreeViewer; import org.eclipse.osgi.util.NLS; import org.eclipse.swt.SWT; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Label; import org.eclipse.ui.PlatformUI; import org.eclipse.ui.part.ViewPart; /** * This class implements the Hierarchy View. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class HierarchyView extends ViewPart { /** The view's ID */ public static final String ID = PluginConstants.VIEW_HIERARCHY_VIEW_ID; /** The tree viewer */ private TreeViewer viewer; /** The controller */ private HierarchyViewController controller; /** The Overview label */ private Label overviewLabel; /** * {@inheritDoc} */ public void createPartControl( Composite parent ) { GridLayout gridLayout = new GridLayout(); gridLayout.horizontalSpacing = 0; gridLayout.marginBottom = 0; gridLayout.marginHeight = 0; gridLayout.marginLeft = 0; gridLayout.marginRight = 0; gridLayout.marginTop = 0; gridLayout.marginWidth = 0; gridLayout.verticalSpacing = 0; parent.setLayout( gridLayout ); // Overview Label overviewLabel = new Label( parent, SWT.WRAP ); overviewLabel.setText( "" ); //$NON-NLS-1$ overviewLabel.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) ); // Separator Label Label separatorLabel = new Label( parent, SWT.SEPARATOR | SWT.HORIZONTAL ); separatorLabel.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) ); initViewer( parent ); controller = new HierarchyViewController( this ); // Help Context for Dynamic Help PlatformUI.getWorkbench().getHelpSystem().setHelp( parent, PluginConstants.PLUGIN_ID + "." + "hierarchy_view" ); //$NON-NLS-1$ //$NON-NLS-2$ } /** * Initializes the Viewer * * @param parent * the parent Composite */ private void initViewer( Composite parent ) { viewer = new TreeViewer( parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL ); viewer.setContentProvider( new HierarchyViewContentProvider() ); viewer.setLabelProvider( new DecoratingLabelProvider( new HierarchyViewLabelProvider( viewer ), Activator .getDefault().getWorkbench().getDecoratorManager().getLabelDecorator() ) ); viewer.getTree().setLayoutData( new GridData( SWT.FILL, SWT.FILL, true, true ) ); viewer.getTree().setEnabled( false ); } /** * {@inheritDoc} */ public void setFocus() { viewer.getControl().setFocus(); } /** * Gets the TreeViewer * * @return * the TreeViewer */ public TreeViewer getViewer() { return viewer; } /** * Refreshes the viewer. */ public void refresh() { viewer.refresh(); viewer.expandAll(); } public void setInput( Object input ) { viewer.setInput( input ); viewer.expandAll(); if ( input == null ) { overviewLabel.setText( "" ); //$NON-NLS-1$ } else { if ( input instanceof AttributeType ) { setOverviewLabel( ( AttributeType ) input ); } else if ( input instanceof ObjectClass ) { setOverviewLabel( ( ObjectClass ) input ); } else { overviewLabel.setText( "" ); //$NON-NLS-1$ } } } /** * Set the overview label for the given schema object. * * @param object * the schema object */ private void setOverviewLabel( SchemaObject object ) { StringBuffer sb = new StringBuffer(); List<String> names = object.getNames(); if ( ( names != null ) && ( names.size() > 0 ) ) { sb.append( ViewUtils.concateAliases( names ) ); } else { sb.append( Messages.getString( "HierarchyView.None" ) ); //$NON-NLS-1$ } sb.append( NLS.bind( Messages.getString( "HierarchyView.Schema" ), new String[] { object.getOid(), object.getSchemaName() } ) ); //$NON-NLS-1$ overviewLabel.setText( sb.toString() ); } /** * {@inheritDoc} */ public void dispose() { controller.dispose(); super.dispose(); } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/views/HierarchyViewLabelProvider.java
plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/views/HierarchyViewLabelProvider.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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.apache.directory.studio.schemaeditor.view.views; import java.util.List; import org.apache.directory.api.ldap.model.schema.AttributeType; import org.apache.directory.api.ldap.model.schema.ObjectClass; import org.apache.directory.studio.schemaeditor.Activator; import org.apache.directory.studio.schemaeditor.PluginConstants; import org.apache.directory.studio.schemaeditor.view.ViewUtils; import org.apache.directory.studio.schemaeditor.view.wrappers.AttributeTypeWrapper; import org.apache.directory.studio.schemaeditor.view.wrappers.ObjectClassWrapper; import org.eclipse.jface.preference.IPreferenceStore; import org.eclipse.jface.viewers.LabelProvider; import org.eclipse.jface.viewers.TreeViewer; import org.eclipse.swt.graphics.Image; import org.eclipse.ui.ISharedImages; import org.eclipse.ui.PlatformUI; /** * This class implements the LabelProvider for the Hierarchy View. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class HierarchyViewLabelProvider extends LabelProvider { /** The preferences store */ private IPreferenceStore store; /** The TreeViewer */ private TreeViewer viewer; /** * Creates a new instance of SchemasViewLabelProvider. */ public HierarchyViewLabelProvider( TreeViewer viewer ) { store = Activator.getDefault().getPreferenceStore(); this.viewer = viewer; } /** * {@inheritDoc} */ public String getText( Object obj ) { String label = ""; //$NON-NLS-1$ int labelValue = store.getInt( PluginConstants.PREFS_HIERARCHY_VIEW_LABEL ); boolean abbreviate = store.getBoolean( PluginConstants.PREFS_HIERARCHY_VIEW_ABBREVIATE ); int abbreviateMaxLength = store.getInt( PluginConstants.PREFS_HIERARCHY_VIEW_ABBREVIATE_MAX_LENGTH ); boolean secondaryLabelDisplay = store.getBoolean( PluginConstants.PREFS_HIERARCHY_VIEW_SECONDARY_LABEL_DISPLAY ); int secondaryLabelValue = store.getInt( PluginConstants.PREFS_HIERARCHY_VIEW_SECONDARY_LABEL ); boolean secondaryLabelAbbreviate = store .getBoolean( PluginConstants.PREFS_HIERARCHY_VIEW_SECONDARY_LABEL_ABBREVIATE ); int secondaryLabelAbbreviateMaxLength = store .getInt( PluginConstants.PREFS_HIERARCHY_VIEW_SECONDARY_LABEL_ABBREVIATE_MAX_LENGTH ); if ( obj instanceof AttributeTypeWrapper ) { AttributeType at = ( ( AttributeTypeWrapper ) obj ).getAttributeType(); // Label if ( labelValue == PluginConstants.PREFS_HIERARCHY_VIEW_LABEL_FIRST_NAME ) { List<String> names = at.getNames(); if ( ( names != null ) && ( names.size() > 0 ) ) { label = names.get( 0 ); } else { label = Messages.getString( "HierarchyViewLabelProvider.None" ); //$NON-NLS-1$ } } else if ( labelValue == PluginConstants.PREFS_HIERARCHY_VIEW_LABEL_ALL_ALIASES ) { List<String> names = at.getNames(); if ( ( names != null ) && ( names.size() > 0 ) ) { label = ViewUtils.concateAliases( names ); } else { label = Messages.getString( "HierarchyViewLabelProvider.None" ); //$NON-NLS-1$ } } else if ( labelValue == PluginConstants.PREFS_HIERARCHY_VIEW_LABEL_OID ) { label = at.getOid(); } else // Default { List<String> names = at.getNames(); if ( ( names != null ) && ( names.size() > 0 ) ) { label = names.get( 0 ); } else { label = Messages.getString( "HierarchyViewLabelProvider.None" ); //$NON-NLS-1$ } } // Abbreviate if ( abbreviate && ( abbreviateMaxLength < label.length() ) ) { label = label.substring( 0, abbreviateMaxLength ) + "..."; //$NON-NLS-1$ } } else if ( obj instanceof ObjectClassWrapper ) { ObjectClass oc = ( ( ObjectClassWrapper ) obj ).getObjectClass(); // Label if ( labelValue == PluginConstants.PREFS_HIERARCHY_VIEW_LABEL_FIRST_NAME ) { List<String> names = oc.getNames(); if ( ( names != null ) && ( names.size() > 0 ) ) { label = names.get( 0 ); } else { label = Messages.getString( "HierarchyViewLabelProvider.None" ); //$NON-NLS-1$ } } else if ( labelValue == PluginConstants.PREFS_HIERARCHY_VIEW_LABEL_ALL_ALIASES ) { List<String> names = oc.getNames(); if ( ( names != null ) && ( names.size() > 0 ) ) { label = ViewUtils.concateAliases( names ); } else { label = Messages.getString( "HierarchyViewLabelProvider.None" ); //$NON-NLS-1$ } } else if ( labelValue == PluginConstants.PREFS_HIERARCHY_VIEW_LABEL_OID ) { label = oc.getOid(); } else // Default { List<String> names = oc.getNames(); if ( ( names != null ) && ( names.size() > 0 ) ) { label = names.get( 0 ); } else { label = Messages.getString( "HierarchyViewLabelProvider.None" ); //$NON-NLS-1$ } } // Abbreviate if ( abbreviate && ( abbreviateMaxLength < label.length() ) ) { label = label.substring( 0, abbreviateMaxLength ) + "..."; //$NON-NLS-1$ } } // Secondary Label if ( secondaryLabelDisplay ) { String secondaryLabel = ""; //$NON-NLS-1$ if ( obj instanceof AttributeTypeWrapper ) { AttributeType at = ( ( AttributeTypeWrapper ) obj ).getAttributeType(); if ( secondaryLabelValue == PluginConstants.PREFS_HIERARCHY_VIEW_LABEL_FIRST_NAME ) { List<String> names = at.getNames(); if ( ( names != null ) && ( names.size() > 0 ) ) { secondaryLabel = names.get( 0 ); } else { secondaryLabel = Messages.getString( "HierarchyViewLabelProvider.None" ); //$NON-NLS-1$ } } else if ( secondaryLabelValue == PluginConstants.PREFS_HIERARCHY_VIEW_LABEL_ALL_ALIASES ) { List<String> names = at.getNames(); if ( ( names != null ) && ( names.size() > 0 ) ) { secondaryLabel = ViewUtils.concateAliases( names ); } else { secondaryLabel = Messages.getString( "HierarchyViewLabelProvider.None" ); //$NON-NLS-1$ } } else if ( secondaryLabelValue == PluginConstants.PREFS_HIERARCHY_VIEW_LABEL_OID ) { secondaryLabel = at.getOid(); } } else if ( obj instanceof ObjectClassWrapper ) { ObjectClass oc = ( ( ObjectClassWrapper ) obj ).getObjectClass(); if ( secondaryLabelValue == PluginConstants.PREFS_HIERARCHY_VIEW_LABEL_FIRST_NAME ) { List<String> names = oc.getNames(); if ( ( names != null ) && ( names.size() > 0 ) ) { secondaryLabel = names.get( 0 ); } else { secondaryLabel = Messages.getString( "HierarchyViewLabelProvider.None" ); //$NON-NLS-1$ } } else if ( secondaryLabelValue == PluginConstants.PREFS_HIERARCHY_VIEW_LABEL_ALL_ALIASES ) { List<String> names = oc.getNames(); if ( ( names != null ) && ( names.size() > 0 ) ) { secondaryLabel = ViewUtils.concateAliases( names ); } else { secondaryLabel = Messages.getString( "HierarchyViewLabelProvider.None" ); //$NON-NLS-1$ } } else if ( secondaryLabelValue == PluginConstants.PREFS_HIERARCHY_VIEW_LABEL_OID ) { secondaryLabel = oc.getOid(); } } if ( secondaryLabelAbbreviate && ( secondaryLabelAbbreviateMaxLength < secondaryLabel.length() ) ) { secondaryLabel = secondaryLabel.substring( 0, secondaryLabelAbbreviateMaxLength ) + "..."; //$NON-NLS-1$ } label += " [" + secondaryLabel + "]"; //$NON-NLS-1$ //$NON-NLS-2$ } return label; } /** * {@inheritDoc} */ public Image getImage( Object obj ) { if ( obj instanceof AttributeTypeWrapper ) { if ( ( ( AttributeTypeWrapper ) obj ).getAttributeType().equals( viewer.getInput() ) ) { return Activator.getDefault().getImage( PluginConstants.IMG_ATTRIBUTE_TYPE_HIERARCHY_SELECTED ); } else { return Activator.getDefault().getImage( PluginConstants.IMG_ATTRIBUTE_TYPE ); } } else if ( obj instanceof ObjectClassWrapper ) { if ( ( ( ObjectClassWrapper ) obj ).getObjectClass().equals( viewer.getInput() ) ) { return Activator.getDefault().getImage( PluginConstants.IMG_OBJECT_CLASS_HIERARCHY_SELECTED ); } else { return Activator.getDefault().getImage( PluginConstants.IMG_OBJECT_CLASS ); } } // Default return PlatformUI.getWorkbench().getSharedImages().getImage( ISharedImages.IMG_OBJS_WARN_TSK ); } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/views/SchemaViewLabelProvider.java
plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/views/SchemaViewLabelProvider.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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.apache.directory.studio.schemaeditor.view.views; import java.util.List; import org.apache.directory.api.ldap.model.schema.AttributeType; import org.apache.directory.api.ldap.model.schema.ObjectClass; import org.apache.directory.studio.schemaeditor.Activator; import org.apache.directory.studio.schemaeditor.PluginConstants; import org.apache.directory.studio.schemaeditor.view.ViewUtils; import org.apache.directory.studio.schemaeditor.view.wrappers.AttributeTypeWrapper; import org.apache.directory.studio.schemaeditor.view.wrappers.Folder; import org.apache.directory.studio.schemaeditor.view.wrappers.ObjectClassWrapper; import org.apache.directory.studio.schemaeditor.view.wrappers.SchemaWrapper; import org.apache.directory.studio.schemaeditor.view.wrappers.TreeNode; import org.eclipse.jface.preference.IPreferenceStore; import org.eclipse.jface.viewers.LabelProvider; import org.eclipse.swt.graphics.Image; /** * This class implements the LabelProvider for the SchemaView. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class SchemaViewLabelProvider extends LabelProvider { /** The preferences store */ private IPreferenceStore store; /** * Creates a new instance of DifferencesWidgetSchemaLabelProvider. */ public SchemaViewLabelProvider() { store = Activator.getDefault().getPreferenceStore(); } /** * {@inheritDoc} */ public String getText( Object element ) { String label = ""; //$NON-NLS-1$ int presentation = store.getInt( PluginConstants.PREFS_SCHEMA_VIEW_SCHEMA_PRESENTATION ); int labelValue = store.getInt( PluginConstants.PREFS_SCHEMA_VIEW_LABEL ); boolean abbreviate = store.getBoolean( PluginConstants.PREFS_SCHEMA_VIEW_ABBREVIATE ); int abbreviateMaxLength = store.getInt( PluginConstants.PREFS_SCHEMA_VIEW_ABBREVIATE_MAX_LENGTH ); boolean secondaryLabelDisplay = store.getBoolean( PluginConstants.PREFS_SCHEMA_VIEW_SECONDARY_LABEL_DISPLAY ); int secondaryLabelValue = store.getInt( PluginConstants.PREFS_SCHEMA_VIEW_SECONDARY_LABEL ); boolean secondaryLabelAbbreviate = store .getBoolean( PluginConstants.PREFS_SCHEMA_VIEW_SECONDARY_LABEL_ABBREVIATE ); int secondaryLabelAbbreviateMaxLength = store .getInt( PluginConstants.PREFS_SCHEMA_VIEW_SECONDARY_LABEL_ABBREVIATE_MAX_LENGTH ); boolean schemaLabelDisplay = store.getBoolean( PluginConstants.PREFS_SCHEMA_VIEW_SCHEMA_LABEL_DISPLAY ); if ( element instanceof SchemaWrapper ) { SchemaWrapper sw = ( SchemaWrapper ) element; return sw.getSchema().getSchemaName(); } else if ( element instanceof AttributeTypeWrapper ) { AttributeType at = ( ( AttributeTypeWrapper ) element ).getAttributeType(); // Label if ( labelValue == PluginConstants.PREFS_SCHEMA_VIEW_LABEL_FIRST_NAME ) { List<String> names = at.getNames(); if ( ( names != null ) && ( names.size() > 0 ) ) { label = names.get( 0 ); } else { label = Messages.getString( "SchemaViewLabelProvider.None" ); //$NON-NLS-1$ } } else if ( labelValue == PluginConstants.PREFS_SCHEMA_VIEW_LABEL_ALL_ALIASES ) { List<String> names = at.getNames(); if ( ( names != null ) && ( names.size() > 0 ) ) { label = ViewUtils.concateAliases( names ); } else { label = Messages.getString( "SchemaViewLabelProvider.None" ); //$NON-NLS-1$ } } else if ( labelValue == PluginConstants.PREFS_SCHEMA_VIEW_LABEL_OID ) { label = at.getOid(); } else // Default { List<String> names = at.getNames(); if ( ( names != null ) && ( names.size() > 0 ) ) { label = names.get( 0 ); } else { label = Messages.getString( "SchemaViewLabelProvider.None" ); //$NON-NLS-1$ } } // Abbreviate if ( abbreviate && ( abbreviateMaxLength < label.length() ) ) { label = label.substring( 0, abbreviateMaxLength ) + "..."; //$NON-NLS-1$ } } else if ( element instanceof ObjectClassWrapper ) { ObjectClass oc = ( ( ObjectClassWrapper ) element ).getObjectClass(); // Label if ( labelValue == PluginConstants.PREFS_SCHEMA_VIEW_LABEL_FIRST_NAME ) { List<String> names = oc.getNames(); if ( ( names != null ) && ( names.size() > 0 ) ) { label = names.get( 0 ); } else { label = Messages.getString( "SchemaViewLabelProvider.None" ); //$NON-NLS-1$ } } else if ( labelValue == PluginConstants.PREFS_SCHEMA_VIEW_LABEL_ALL_ALIASES ) { List<String> names = oc.getNames(); if ( ( names != null ) && ( names.size() > 0 ) ) { label = ViewUtils.concateAliases( names ); } else { label = Messages.getString( "SchemaViewLabelProvider.None" ); //$NON-NLS-1$ } } else if ( labelValue == PluginConstants.PREFS_SCHEMA_VIEW_LABEL_OID ) { label = oc.getOid(); } else // Default { List<String> names = oc.getNames(); if ( ( names != null ) && ( names.size() > 0 ) ) { label = names.get( 0 ); } else { label = Messages.getString( "SchemaViewLabelProvider.None" ); //$NON-NLS-1$ } } // Abbreviate if ( abbreviate && ( abbreviateMaxLength < label.length() ) ) { label = label.substring( 0, abbreviateMaxLength ) + "..."; //$NON-NLS-1$ } } else if ( element instanceof Folder ) { Folder folder = ( Folder ) element; if ( presentation == PluginConstants.PREFS_SCHEMA_VIEW_SCHEMA_PRESENTATION_FLAT ) { return folder.getName() + " (" + folder.getChildren().size() + ")"; //$NON-NLS-1$ //$NON-NLS-2$ } else if ( presentation == PluginConstants.PREFS_SCHEMA_VIEW_SCHEMA_PRESENTATION_HIERARCHICAL ) { return folder.getName(); } } // Secondary Label if ( secondaryLabelDisplay ) { String secondaryLabel = ""; //$NON-NLS-1$ if ( element instanceof AttributeTypeWrapper ) { AttributeType at = ( ( AttributeTypeWrapper ) element ).getAttributeType(); if ( secondaryLabelValue == PluginConstants.PREFS_SCHEMA_VIEW_LABEL_FIRST_NAME ) { List<String> names = at.getNames(); if ( ( names != null ) && ( names.size() > 0 ) ) { secondaryLabel = names.get( 0 ); } else { secondaryLabel = Messages.getString( "SchemaViewLabelProvider.None" ); //$NON-NLS-1$ } } else if ( secondaryLabelValue == PluginConstants.PREFS_SCHEMA_VIEW_LABEL_ALL_ALIASES ) { List<String> names = at.getNames(); if ( ( names != null ) && ( names.size() > 0 ) ) { secondaryLabel = ViewUtils.concateAliases( names ); } else { secondaryLabel = Messages.getString( "SchemaViewLabelProvider.None" ); //$NON-NLS-1$ } } else if ( secondaryLabelValue == PluginConstants.PREFS_SCHEMA_VIEW_LABEL_OID ) { secondaryLabel = at.getOid(); } } else if ( element instanceof ObjectClassWrapper ) { ObjectClass oc = ( ( ObjectClassWrapper ) element ).getObjectClass(); if ( secondaryLabelValue == PluginConstants.PREFS_SCHEMA_VIEW_LABEL_FIRST_NAME ) { List<String> names = oc.getNames(); if ( ( names != null ) && ( names.size() > 0 ) ) { secondaryLabel = names.get( 0 ); } else { secondaryLabel = Messages.getString( "SchemaViewLabelProvider.None" ); //$NON-NLS-1$ } } else if ( secondaryLabelValue == PluginConstants.PREFS_SCHEMA_VIEW_LABEL_ALL_ALIASES ) { List<String> names = oc.getNames(); if ( ( names != null ) && ( names.size() > 0 ) ) { secondaryLabel = ViewUtils.concateAliases( names ); } else { secondaryLabel = Messages.getString( "SchemaViewLabelProvider.None" ); //$NON-NLS-1$ } } else if ( secondaryLabelValue == PluginConstants.PREFS_SCHEMA_VIEW_LABEL_OID ) { secondaryLabel = oc.getOid(); } } if ( secondaryLabelAbbreviate && ( secondaryLabelAbbreviateMaxLength < secondaryLabel.length() ) ) { secondaryLabel = secondaryLabel.substring( 0, secondaryLabelAbbreviateMaxLength ) + "..."; //$NON-NLS-1$ } label += " [" + secondaryLabel + "]"; //$NON-NLS-1$ //$NON-NLS-2$ } // Number of children if ( presentation == PluginConstants.PREFS_SCHEMA_VIEW_SCHEMA_PRESENTATION_HIERARCHICAL ) { if ( ( element instanceof AttributeTypeWrapper ) || ( element instanceof ObjectClassWrapper ) ) { List<TreeNode> children = ( ( TreeNode ) element ).getChildren(); if ( ( children != null ) && ( children.size() > 0 ) ) { label += " (" + children.size() + ")"; //$NON-NLS-1$ //$NON-NLS-2$ } } } // Schema Label if ( schemaLabelDisplay ) { if ( element instanceof AttributeTypeWrapper ) { label += " [" + ( ( AttributeTypeWrapper ) element ).getAttributeType().getSchemaName() + "]"; //$NON-NLS-1$ //$NON-NLS-2$ } else if ( element instanceof ObjectClassWrapper ) { label += " [" + ( ( ObjectClassWrapper ) element ).getObjectClass().getSchemaName() + "]"; //$NON-NLS-1$ //$NON-NLS-2$ } } return label; } /** * {@inheritDoc} */ public Image getImage( Object element ) { if ( element instanceof SchemaWrapper ) { return Activator.getDefault().getImage( PluginConstants.IMG_SCHEMA ); } else if ( element instanceof AttributeTypeWrapper ) { return Activator.getDefault().getImage( PluginConstants.IMG_ATTRIBUTE_TYPE ); } else if ( element instanceof ObjectClassWrapper ) { return Activator.getDefault().getImage( PluginConstants.IMG_OBJECT_CLASS ); } else if ( element instanceof Folder ) { Folder folder = ( Folder ) element; switch ( folder.getType() ) { case ATTRIBUTE_TYPE: return Activator.getDefault().getImage( PluginConstants.IMG_FOLDER_AT ); case OBJECT_CLASS: return Activator.getDefault().getImage( PluginConstants.IMG_FOLDER_OC ); case NONE: return Activator.getDefault().getImage( PluginConstants.IMG_FOLDER ); default: break; } } // Default return null; } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/views/SchemaView.java
plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/views/SchemaView.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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.apache.directory.studio.schemaeditor.view.views; import org.apache.directory.studio.schemaeditor.Activator; import org.apache.directory.studio.schemaeditor.PluginConstants; import org.apache.directory.studio.schemaeditor.controller.SchemaViewController; import org.apache.directory.studio.schemaeditor.view.wrappers.SchemaViewRoot; import org.eclipse.jface.viewers.DecoratingLabelProvider; import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.TreeViewer; import org.eclipse.swt.SWT; import org.eclipse.swt.widgets.Composite; import org.eclipse.ui.PlatformUI; import org.eclipse.ui.part.ViewPart; /** * This class represents the SchemaView. * It is used to display the Schema and its elements (Schemas, AttributeTypes * and ObjectClasses). * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class SchemaView extends ViewPart { /** The ID of the View */ public static final String ID = PluginConstants.VIEW_SCHEMA_VIEW_ID; /** The viewer */ private TreeViewer treeViewer; /** * {@inheritDoc} */ public void createPartControl( Composite parent ) { initViewer( parent ); // Registering the Viewer, so other views can be notified when the viewer selection changes getSite().setSelectionProvider( treeViewer ); // Adding the controller new SchemaViewController( this ); // Help Context for Dynamic Help PlatformUI.getWorkbench().getHelpSystem().setHelp( parent, PluginConstants.PLUGIN_ID + "." + "schema_view" ); //$NON-NLS-1$ //$NON-NLS-2$ } /** * Initializes the Viewer */ private void initViewer( Composite parent ) { treeViewer = new TreeViewer( parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER ); treeViewer.setContentProvider( new SchemaViewContentProvider() ); treeViewer.setLabelProvider( new DecoratingLabelProvider( new SchemaViewLabelProvider(), Activator.getDefault() .getWorkbench().getDecoratorManager().getLabelDecorator() ) ); treeViewer.getTree().setEnabled( false ); } /** * {@inheritDoc} */ public void setFocus() { treeViewer.getTree().setFocus(); } /** * Gets the TreeViewer. * * @return * the TreeViewer */ public TreeViewer getViewer() { return treeViewer; } /** * Reloads the Viewer */ public void reloadViewer() { treeViewer.setInput( new SchemaViewRoot() ); } /** * Refreshes the viewer */ public void refresh() { treeViewer.refresh(); } /** * Refreshes the viewer and selects the given selection */ public void refresh( ISelection selection ) { treeViewer.refresh(); treeViewer.setSelection( selection ); } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/views/ProblemsViewLabelProvider.java
plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/views/ProblemsViewLabelProvider.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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.apache.directory.studio.schemaeditor.view.views; import org.apache.directory.api.ldap.model.exception.LdapSchemaException; import org.apache.directory.api.ldap.model.schema.AttributeType; import org.apache.directory.api.ldap.model.schema.LdapSyntax; import org.apache.directory.api.ldap.model.schema.MatchingRule; import org.apache.directory.api.ldap.model.schema.ObjectClass; import org.apache.directory.api.ldap.model.schema.SchemaObject; import org.apache.directory.studio.schemaeditor.Activator; import org.apache.directory.studio.schemaeditor.PluginConstants; import org.apache.directory.studio.schemaeditor.controller.SchemaHandler; import org.apache.directory.studio.schemaeditor.model.schemachecker.NoAliasWarning; import org.apache.directory.studio.schemaeditor.model.schemachecker.SchemaWarning; import org.apache.directory.studio.schemaeditor.view.wrappers.Folder; import org.apache.directory.studio.schemaeditor.view.wrappers.SchemaErrorWrapper; import org.apache.directory.studio.schemaeditor.view.wrappers.SchemaWarningWrapper; import org.eclipse.jface.viewers.ITableLabelProvider; import org.eclipse.jface.viewers.LabelProvider; import org.eclipse.osgi.util.NLS; import org.eclipse.swt.graphics.Image; /** * This class implements the LabelProvider for the SchemaView. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class ProblemsViewLabelProvider extends LabelProvider implements ITableLabelProvider { /** * {@inheritDoc} */ public Image getColumnImage( Object element, int columnIndex ) { if ( columnIndex == 0 ) { if ( element instanceof SchemaErrorWrapper ) { return Activator.getDefault().getImage( PluginConstants.IMG_PROBLEMS_ERROR ); } else if ( element instanceof SchemaWarningWrapper ) { return Activator.getDefault().getImage( PluginConstants.IMG_PROBLEMS_WARNING ); } else if ( element instanceof Folder ) { return Activator.getDefault().getImage( PluginConstants.IMG_PROBLEMS_GROUP ); } } // Default return null; } /** * {@inheritDoc} */ public String getColumnText( Object element, int columnIndex ) { if ( element instanceof SchemaErrorWrapper ) { SchemaErrorWrapper errorWrapper = ( SchemaErrorWrapper ) element; if ( columnIndex == 0 ) { return getMessage( errorWrapper.getLdapSchemaException() ); } else if ( columnIndex == 1 ) { return getDisplayName( errorWrapper.getLdapSchemaException().getSourceObject() ); } } else if ( element instanceof SchemaWarningWrapper ) { SchemaWarningWrapper warningWrapper = ( SchemaWarningWrapper ) element; if ( columnIndex == 0 ) { return getMessage( warningWrapper.getSchemaWarning() ); } else if ( columnIndex == 1 ) { String name = warningWrapper.getSchemaWarning().getSource().getName(); if ( ( name != null ) && ( !name.equals( "" ) ) ) //$NON-NLS-1$ { return name; } else { return warningWrapper.getSchemaWarning().getSource().getOid(); } } } else if ( element instanceof Folder ) { Folder folder = ( Folder ) element; if ( columnIndex == 0 ) { return folder.getName() + " (" + folder.getChildren().size() + ")"; //$NON-NLS-1$ //$NON-NLS-2$ } else { return ""; //$NON-NLS-1$ } } // Default return element.toString(); } private String getMessage( LdapSchemaException exception ) { if ( exception != null ) { switch ( exception.getCode() ) { // Codes for all Schema Objects case NAME_ALREADY_REGISTERED: return getMessageNameAlreadyRegistered( exception ); case OID_ALREADY_REGISTERED: return getMessageOidAlreadyRegistered( exception ); case NONEXISTENT_SCHEMA: return getMessageNonExistentSchema( exception ); // Codes for Attribute Type case AT_NONEXISTENT_SUPERIOR: return getMessageATNonExistentSuperior( exception ); case AT_CANNOT_SUBTYPE_COLLECTIVE_AT: return getMessageATCannotSubtypeCollectiveAT( exception ); case AT_CYCLE_TYPE_HIERARCHY: return getMessageATCycleTypeHierarchy( exception ); case AT_NONEXISTENT_SYNTAX: return getMessageATNonExistentSyntax( exception ); case AT_SYNTAX_OR_SUPERIOR_REQUIRED: return getMessageATSyntaxOrSuperiorRequired( exception ); case AT_NONEXISTENT_EQUALITY_MATCHING_RULE: return getMessageATNonExistentEqualityMatchingRule( exception ); case AT_NONEXISTENT_ORDERING_MATCHING_RULE: return getMessageATNonExistentOrderingMatchingRule( exception ); case AT_NONEXISTENT_SUBSTRING_MATCHING_RULE: return getMessageATNonExistentSubstringMatchingRule( exception ); case AT_MUST_HAVE_SAME_USAGE_THAN_SUPERIOR: return getMessageATMustHaveSameUsageThanSuperior( exception ); case AT_USER_APPLICATIONS_USAGE_MUST_BE_USER_MODIFIABLE: return getMessageATUserApplicationsUsageMustBeUserModifiable( exception ); case AT_COLLECTIVE_MUST_HAVE_USER_APPLICATIONS_USAGE: return getMessageATCollectiveMustHaveUserApplicationsUsage( exception ); case AT_COLLECTIVE_CANNOT_BE_SINGLE_VALUED: return getMessageATCollectiveCannotBeSingleValued( exception ); // Codes for Object Class case OC_ABSTRACT_MUST_INHERIT_FROM_ABSTRACT_OC: return getMessageOCAbstractMustInheritFromAbstractOC( exception ); case OC_AUXILIARY_CANNOT_INHERIT_FROM_STRUCTURAL_OC: return getMessageOCAuxiliaryCannotInheritFromStructuralOC( exception ); case OC_STRUCTURAL_CANNOT_INHERIT_FROM_AUXILIARY_OC: return getMessageOCStructuralCannotInheritFromAuxiliaryOC( exception ); case OC_NONEXISTENT_SUPERIOR: return getMessageOCNonExistentSuperior( exception ); case OC_CYCLE_CLASS_HIERARCHY: return getMessageOCCycleClassHierarchy( exception ); case OC_COLLECTIVE_NOT_ALLOWED_IN_MUST: return getMessageOCCollectiveNotAllowedInMust( exception ); case OC_COLLECTIVE_NOT_ALLOWED_IN_MAY: return getMessageOCCollectiveNotAllowedInMay( exception ); case OC_DUPLICATE_AT_IN_MUST: return getMessageOCDuplicateATInMust( exception ); case OC_DUPLICATE_AT_IN_MAY: return getMessageOCDuplicateATInMay( exception ); case OC_NONEXISTENT_MUST_AT: return getMessageOCNonExistentMustAT( exception ); case OC_NONEXISTENT_MAY_AT: return getMessageOCNonExistentMayAT( exception ); case OC_DUPLICATE_AT_IN_MAY_AND_MUST: return getMessageOCDuplicateATInMayAndMust( exception ); // Codes for Matching Rule case MR_NONEXISTENT_SYNTAX: return getMessageMRNonExistentSyntax( exception ); } } return ""; //$NON-NLS-1$ } private String getMessage( SchemaWarning warning ) { if ( warning instanceof NoAliasWarning ) { NoAliasWarning noAliasWarning = ( NoAliasWarning ) warning; SchemaObject source = noAliasWarning.getSource(); if ( source instanceof AttributeType ) { return NLS .bind( Messages.getString( "ProblemsViewLabelProvider.NoAliasWarningAttributeType" ), new String[] { source.getOid() } ); //$NON-NLS-1$ } else if ( source instanceof ObjectClass ) { return NLS .bind( Messages.getString( "ProblemsViewLabelProvider.NoAliasWarningObjectClass" ), new String[] { source.getOid() } ); //$NON-NLS-1$ } } return ""; //$NON-NLS-1$ } private String getMessageNameAlreadyRegistered( LdapSchemaException exception ) { SchemaObject duplicate = exception.getOtherObject(); String message = null; if ( duplicate instanceof AttributeType ) { message = Messages.getString( "ProblemsViewLabelProvider.NameAlreadyRegisteredAT" ); //$NON-NLS-1$ } else if ( duplicate instanceof ObjectClass ) { message = Messages.getString( "ProblemsViewLabelProvider.NameAlreadyRegisteredOC" ); //$NON-NLS-1$ } return NLS.bind( message, new String[] { exception.getRelatedId(), duplicate.getOid() } ); } private String getMessageOidAlreadyRegistered( LdapSchemaException exception ) { SchemaObject duplicate = exception.getOtherObject(); String message = null; if ( duplicate instanceof AttributeType ) { message = Messages.getString( "ProblemsViewLabelProvider.OidAlreadyRegisteredAT" ); //$NON-NLS-1$ } else if ( duplicate instanceof ObjectClass ) { message = Messages.getString( "ProblemsViewLabelProvider.OidAlreadyRegisteredOC" ); //$NON-NLS-1$ } return NLS.bind( message, new String[] { exception.getRelatedId(), duplicate.getName() } ); } private String getMessageNonExistentSchema( LdapSchemaException exception ) { return NLS.bind( Messages.getString( "ProblemsViewLabelProvider.NonExistentSchema" ), new String[]//$NON-NLS-1$ { exception.getRelatedId() } ); } private String getMessageATNonExistentSuperior( LdapSchemaException exception ) { return NLS.bind( Messages.getString( "ProblemsViewLabelProvider.ATNonExistentSuperior" ), new String[]//$NON-NLS-1$ { exception.getRelatedId() } ); } private String getMessageATCannotSubtypeCollectiveAT( LdapSchemaException exception ) { return Messages.getString( "ProblemsViewLabelProvider.ATCannotSubtypeCollectiveAT" ); //$NON-NLS-1$; } private String getMessageATCycleTypeHierarchy( LdapSchemaException exception ) { return Messages.getString( "ProblemsViewLabelProvider.ATCycleTypeHierarchy" ); //$NON-NLS-1$; } private String getMessageATNonExistentSyntax( LdapSchemaException exception ) { return NLS.bind( Messages.getString( "ProblemsViewLabelProvider.NonExistentSyntax" ), new String[]//$NON-NLS-1$ { exception.getRelatedId() } ); } private String getMessageATSyntaxOrSuperiorRequired( LdapSchemaException exception ) { return NLS.bind( Messages.getString( "ProblemsViewLabelProvider.ATSyntaxOrSuperiorRequired" ), new String[]//$NON-NLS-1$ { exception.getRelatedId() } ); } private String getMessageATNonExistentEqualityMatchingRule( LdapSchemaException exception ) { return NLS.bind( Messages.getString( "ProblemsViewLabelProvider.ATNonExistentEqualityMatchingRule" ), new String[]//$NON-NLS-1$ { exception.getRelatedId() } ); } private String getMessageATNonExistentOrderingMatchingRule( LdapSchemaException exception ) { return NLS.bind( Messages.getString( "ProblemsViewLabelProvider.ATNonExistentOrderingMatchingRule" ), new String[]//$NON-NLS-1$ { exception.getRelatedId() } ); } private String getMessageATNonExistentSubstringMatchingRule( LdapSchemaException exception ) { return NLS.bind( Messages.getString( "ProblemsViewLabelProvider.ATNonExistentSubstringMatchingRule" ), new String[]//$NON-NLS-1$ { exception.getRelatedId() } ); } private String getMessageATMustHaveSameUsageThanSuperior( LdapSchemaException exception ) { return Messages.getString( "ProblemsViewLabelProvider.ATMustHaveSameUsageThanSuperior" ); //$NON-NLS-1$ } private String getMessageATUserApplicationsUsageMustBeUserModifiable( LdapSchemaException exception ) { return Messages.getString( "ProblemsViewLabelProvider.ATUserApplicationsUsageMustBeUserModifiable" ); //$NON-NLS-1$ } private String getMessageATCollectiveMustHaveUserApplicationsUsage( LdapSchemaException exception ) { return Messages.getString( "ProblemsViewLabelProvider.ATCollectiveMustHaveUserApplicationsUsage" ); //$NON-NLS-1$ } private String getMessageATCollectiveCannotBeSingleValued( LdapSchemaException exception ) { return Messages.getString( "ProblemsViewLabelProvider.ATCollectiveCannotBeSingleValued" ); //$NON-NLS-1$ } private String getMessageOCAbstractMustInheritFromAbstractOC( LdapSchemaException exception ) { return Messages.getString( "ProblemsViewLabelProvider.OCAbstractMustInheritFromAbstractOC" ); //$NON-NLS-1$ } private String getMessageOCAuxiliaryCannotInheritFromStructuralOC( LdapSchemaException exception ) { return Messages.getString( "ProblemsViewLabelProvider.OCAuxiliaryCannotInheritFromStructuralOC" ); //$NON-NLS-1$ } private String getMessageOCStructuralCannotInheritFromAuxiliaryOC( LdapSchemaException exception ) { return Messages.getString( "ProblemsViewLabelProvider.OCStructuralCannotInheritFromAuxiliaryOC" ); //$NON-NLS-1$ } private String getMessageOCNonExistentSuperior( LdapSchemaException exception ) { return NLS.bind( Messages.getString( "ProblemsViewLabelProvider.OCNonExistentSuperior" ), new String[]//$NON-NLS-1$ { exception.getRelatedId() } ); } private String getMessageOCCycleClassHierarchy( LdapSchemaException exception ) { return Messages.getString( "ProblemsViewLabelProvider.OCCycleClassHierarchy" ); //$NON-NLS-1$ } private String getMessageOCCollectiveNotAllowedInMust( LdapSchemaException exception ) { return NLS.bind( Messages.getString( "ProblemsViewLabelProvider.OCCollectiveNotAllowedInMust" ), new String[]//$NON-NLS-1$ { exception.getRelatedId() } ); } private String getMessageOCCollectiveNotAllowedInMay( LdapSchemaException exception ) { return NLS.bind( Messages.getString( "ProblemsViewLabelProvider.OCCollectiveNotAllowedInMay" ), new String[]//$NON-NLS-1$ { exception.getRelatedId() } ); } private String getMessageOCDuplicateATInMust( LdapSchemaException exception ) { return NLS.bind( Messages.getString( "ProblemsViewLabelProvider.OCDuplicateATInMust" ), new String[]//$NON-NLS-1$ { exception.getRelatedId() } ); } private String getMessageOCDuplicateATInMay( LdapSchemaException exception ) { return NLS.bind( Messages.getString( "ProblemsViewLabelProvider.OCDuplicateATInMay" ), new String[]//$NON-NLS-1$ { exception.getRelatedId() } ); } private String getMessageOCNonExistentMustAT( LdapSchemaException exception ) { return NLS.bind( Messages.getString( "ProblemsViewLabelProvider.OCNonExistentMustAT" ), new String[]//$NON-NLS-1$ { exception.getRelatedId() } ); } private String getMessageOCNonExistentMayAT( LdapSchemaException exception ) { return NLS.bind( Messages.getString( "ProblemsViewLabelProvider.OCNonExistentMayAT" ), new String[] //$NON-NLS-1$ { exception.getRelatedId() } ); } private String getMessageOCDuplicateATInMayAndMust( LdapSchemaException exception ) { return NLS.bind( Messages.getString( "ProblemsViewLabelProvider.OCDuplicateATInMayAndMust" ), new String[] //$NON-NLS-1$; { exception.getRelatedId() } ); } private String getMessageMRNonExistentSyntax( LdapSchemaException exception ) { return NLS.bind( Messages.getString( "ProblemsViewLabelProvider.NonExistentSyntax" ), new String[] //$NON-NLS-1$; { exception.getRelatedId() } ); } /** * Gets the displayable name of the given SchemaObject. * * @param so * the SchemaObject * @return * the displayable name of the given SchemaObject */ private String getDisplayName( SchemaObject so ) { if ( so != null ) { SchemaObject schemaObject = getSchemaObject( so ); if ( schemaObject != null ) { String name = schemaObject.getName(); if ( ( name != null ) && ( !name.equals( "" ) ) ) // $NON-NLS-1$ //$NON-NLS-1$ { return name; } else { return so.getOid(); } } else { return so.getOid(); } } return ""; // $NON-NLS-1$ //$NON-NLS-1$ } /** * Gets the original {@link SchemaObject} from the {@link SchemaHandler}. * * @param so * the schema object * @return * the original schema object from the schema handler. */ private SchemaObject getSchemaObject( SchemaObject so ) { SchemaHandler schemaHandler = Activator.getDefault().getSchemaHandler(); SchemaObject schemaObject = null; if ( so instanceof AttributeType ) { schemaObject = schemaHandler.getAttributeType( so.getOid() ); } else if ( so instanceof LdapSyntax ) { schemaObject = schemaHandler.getSyntax( so.getOid() ); } else if ( so instanceof MatchingRule ) { schemaObject = schemaHandler.getMatchingRule( so.getOid() ); } else if ( so instanceof ObjectClass ) { schemaObject = schemaHandler.getObjectClass( so.getOid() ); } return schemaObject; } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/views/Messages.java
plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/views/Messages.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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.apache.directory.studio.schemaeditor.view.views; import java.util.MissingResourceException; import java.util.ResourceBundle; /** * This class get messages from the resources file. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class Messages { /** The resource name */ private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle.getBundle( Messages.class.getPackage().getName() + ".messages" ); /** * Get back a message from the resource file given a key * * @param key The key associated with the message * @return The found message */ public static String getString( String key ) { try { return RESOURCE_BUNDLE.getString( key ); } catch ( MissingResourceException e ) { return '!' + key + '!'; } } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/views/SearchViewSortingDialog.java
plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/views/SearchViewSortingDialog.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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.apache.directory.studio.schemaeditor.view.views; import org.apache.directory.studio.schemaeditor.Activator; import org.apache.directory.studio.schemaeditor.PluginConstants; import org.eclipse.jface.dialogs.Dialog; import org.eclipse.jface.dialogs.IDialogConstants; import org.eclipse.jface.preference.IPreferenceStore; import org.eclipse.swt.SWT; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Combo; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Group; import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Shell; /** * This class implements the SearchView Sorting Dialog. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class SearchViewSortingDialog extends Dialog { // UI Fields private Button attributeTypesFirst; private Button objectClassesFirst; private Button mixedButton; private Combo sortingCombo; private Button ascendingButton; private Button descendingButton; /** * Creates a new instance of SearchViewSortingDialog. * * @param parentShell * the parent shell */ public SearchViewSortingDialog( Shell parentShell ) { super( parentShell ); } /** * {@inheritDoc} */ protected void configureShell( Shell newShell ) { super.configureShell( newShell ); newShell.setText( Messages.getString( "SearchViewSortingDialog.ViewSorting" ) ); //$NON-NLS-1$ } /** * {@inheritDoc} */ protected Control createDialogArea( Composite parent ) { Composite composite = ( Composite ) super.createDialogArea( parent ); GridData gd = new GridData( SWT.FILL, SWT.FILL, true, true ); composite.setLayoutData( gd ); // Grouping Group Group groupingGroup = new Group( composite, SWT.NONE ); groupingGroup.setLayoutData( new GridData( SWT.FILL, SWT.FILL, true, true ) ); groupingGroup.setText( Messages.getString( "SearchViewSortingDialog.Grouping" ) ); //$NON-NLS-1$ groupingGroup.setLayout( new GridLayout() ); // Attribute Types first Button attributeTypesFirst = new Button( groupingGroup, SWT.RADIO ); attributeTypesFirst.setText( Messages.getString( "SearchViewSortingDialog.TypesFirst" ) ); //$NON-NLS-1$ attributeTypesFirst.setEnabled( true ); // Object Classes first Button objectClassesFirst = new Button( groupingGroup, SWT.RADIO ); objectClassesFirst.setText( Messages.getString( "SearchViewSortingDialog.ClassesFirst" ) ); //$NON-NLS-1$ objectClassesFirst.setEnabled( true ); // Mixed Button mixedButton = new Button( groupingGroup, SWT.RADIO ); mixedButton.setText( Messages.getString( "SearchViewSortingDialog.Mixed" ) ); //$NON-NLS-1$ mixedButton.setEnabled( true ); // Sorting Group Group sortingGroup = new Group( composite, SWT.NONE ); sortingGroup.setLayoutData( new GridData( SWT.FILL, SWT.FILL, true, true ) ); sortingGroup.setText( Messages.getString( "SearchViewSortingDialog.Sorting" ) ); //$NON-NLS-1$ sortingGroup.setLayout( new GridLayout() ); Composite sortingGroupComposite = new Composite( sortingGroup, SWT.NONE ); GridLayout gl = new GridLayout( 4, false ); gl.marginHeight = gl.marginWidth = 0; sortingGroupComposite.setLayout( gl ); sortingGroupComposite.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) ); // Sort by Label Label sortByLabel = new Label( sortingGroupComposite, SWT.NONE ); sortByLabel.setText( Messages.getString( "SearchViewSortingDialog.SortBy" ) ); //$NON-NLS-1$ // Sorting Combo sortingCombo = new Combo( sortingGroupComposite, SWT.DROP_DOWN | SWT.READ_ONLY | SWT.BORDER ); sortingCombo.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) ); sortingCombo .setItems( new String[] { Messages.getString( "SearchViewSortingDialog.FirstName" ), Messages.getString( "SearchViewSortingDialog.OID" ) } ); //$NON-NLS-1$ //$NON-NLS-2$ sortingCombo.setEnabled( true ); // Ascending Button ascendingButton = new Button( sortingGroupComposite, SWT.RADIO ); ascendingButton.setText( Messages.getString( "SearchViewSortingDialog.Ascending" ) ); //$NON-NLS-1$ ascendingButton.setEnabled( true ); // Descending Button descendingButton = new Button( sortingGroupComposite, SWT.RADIO ); descendingButton.setText( Messages.getString( "SearchViewSortingDialog.Descending" ) ); //$NON-NLS-1$ descendingButton.setEnabled( true ); initFieldsFromPreferences(); applyDialogFont( composite ); return composite; } /** * Initializes the fields for the stored preferences. */ private void initFieldsFromPreferences() { IPreferenceStore store = Activator.getDefault().getPreferenceStore(); int grouping = store.getInt( PluginConstants.PREFS_SEARCH_VIEW_GROUPING ); if ( grouping == PluginConstants.PREFS_SEARCH_VIEW_GROUPING_ATTRIBUTE_TYPES_FIRST ) { attributeTypesFirst.setSelection( true ); } else if ( grouping == PluginConstants.PREFS_SEARCH_VIEW_GROUPING_OBJECT_CLASSES_FIRST ) { objectClassesFirst.setSelection( true ); } else if ( grouping == PluginConstants.PREFS_SEARCH_VIEW_GROUPING_MIXED ) { mixedButton.setSelection( true ); } int sortingBy = store.getInt( PluginConstants.PREFS_SEARCH_VIEW_SORTING_BY ); if ( sortingBy == PluginConstants.PREFS_SEARCH_VIEW_SORTING_BY_FIRSTNAME ) { sortingCombo.select( 0 ); } else if ( sortingBy == PluginConstants.PREFS_SEARCH_VIEW_SORTING_BY_OID ) { sortingCombo.select( 1 ); } int sortingOrder = store.getInt( PluginConstants.PREFS_SEARCH_VIEW_SORTING_ORDER ); if ( sortingOrder == PluginConstants.PREFS_SEARCH_VIEW_SORTING_ORDER_ASCENDING ) { ascendingButton.setSelection( true ); } else if ( sortingOrder == PluginConstants.PREFS_SEARCH_VIEW_SORTING_ORDER_DESCENDING ) { descendingButton.setSelection( true ); } } /** * {@inheritDoc} */ protected void buttonPressed( int buttonId ) { if ( buttonId == IDialogConstants.OK_ID ) { IPreferenceStore store = Activator.getDefault().getPreferenceStore(); if ( ( attributeTypesFirst.getSelection() ) && ( !objectClassesFirst.getSelection() ) && ( !mixedButton.getSelection() ) ) { store.setValue( PluginConstants.PREFS_SEARCH_VIEW_GROUPING, PluginConstants.PREFS_SEARCH_VIEW_GROUPING_ATTRIBUTE_TYPES_FIRST ); } else if ( ( !attributeTypesFirst.getSelection() ) && ( objectClassesFirst.getSelection() ) && ( !mixedButton.getSelection() ) ) { store.setValue( PluginConstants.PREFS_SEARCH_VIEW_GROUPING, PluginConstants.PREFS_SEARCH_VIEW_GROUPING_OBJECT_CLASSES_FIRST ); } else if ( ( !attributeTypesFirst.getSelection() ) && ( !objectClassesFirst.getSelection() ) && ( mixedButton.getSelection() ) ) { store.setValue( PluginConstants.PREFS_SEARCH_VIEW_GROUPING, PluginConstants.PREFS_SEARCH_VIEW_GROUPING_MIXED ); } if ( sortingCombo.getItem( sortingCombo.getSelectionIndex() ).equals( Messages.getString( "SearchViewSortingDialog.FirstName" ) ) ) //$NON-NLS-1$ { store.setValue( PluginConstants.PREFS_SEARCH_VIEW_SORTING_BY, PluginConstants.PREFS_SEARCH_VIEW_SORTING_BY_FIRSTNAME ); } else if ( sortingCombo.getItem( sortingCombo.getSelectionIndex() ).equals( Messages.getString( "SearchViewSortingDialog.OID" ) ) ) //$NON-NLS-1$ { store.setValue( PluginConstants.PREFS_SEARCH_VIEW_SORTING_BY, PluginConstants.PREFS_SEARCH_VIEW_SORTING_BY_OID ); } if ( ascendingButton.getSelection() && !descendingButton.getSelection() ) { store.setValue( PluginConstants.PREFS_SEARCH_VIEW_SORTING_ORDER, PluginConstants.PREFS_SEARCH_VIEW_SORTING_ORDER_ASCENDING ); } else if ( !ascendingButton.getSelection() && descendingButton.getSelection() ) { store.setValue( PluginConstants.PREFS_SEARCH_VIEW_SORTING_ORDER, PluginConstants.PREFS_SEARCH_VIEW_SORTING_ORDER_DESCENDING ); } } super.buttonPressed( buttonId ); } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/views/ProjectsViewLabelProvider.java
plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/views/ProjectsViewLabelProvider.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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.apache.directory.studio.schemaeditor.view.views; import org.apache.directory.studio.schemaeditor.Activator; import org.apache.directory.studio.schemaeditor.PluginConstants; import org.apache.directory.studio.schemaeditor.model.Project; import org.apache.directory.studio.schemaeditor.model.Project.ProjectState; import org.apache.directory.studio.schemaeditor.model.ProjectType; import org.apache.directory.studio.schemaeditor.view.wrappers.ProjectWrapper; import org.eclipse.jface.viewers.LabelProvider; import org.eclipse.swt.graphics.Image; /** * This class implements the LabelProvider for the ProjectsView. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class ProjectsViewLabelProvider extends LabelProvider { /** * {@inheritDoc} */ public Image getImage( Object element ) { if ( element instanceof ProjectWrapper ) { Project project = ( ( ProjectWrapper ) element ).getProject(); ProjectType type = project.getType(); switch ( type ) { case OFFLINE: ProjectState state = project.getState(); switch ( state ) { case OPEN: return Activator.getDefault().getImage( PluginConstants.IMG_PROJECT_OFFLINE ); case CLOSED: return Activator.getDefault().getImage( PluginConstants.IMG_PROJECT_OFFLINE_CLOSED ); } case ONLINE: ProjectState state2 = project.getState(); switch ( state2 ) { case OPEN: return Activator.getDefault().getImage( PluginConstants.IMG_PROJECT_ONLINE ); case CLOSED: return Activator.getDefault().getImage( PluginConstants.IMG_PROJECT_ONLINE_CLOSED ); } } } // Default return super.getImage( element ); } /** * {@inheritDoc} */ public String getText( Object element ) { if ( element instanceof ProjectWrapper ) { ProjectWrapper projectWrapper = ( ProjectWrapper ) element; return projectWrapper.getProject().getName(); } // Default return super.getText( element ); } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/views/ProjectsView.java
plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/views/ProjectsView.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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.apache.directory.studio.schemaeditor.view.views; import org.apache.directory.studio.schemaeditor.Activator; import org.apache.directory.studio.schemaeditor.PluginConstants; import org.apache.directory.studio.schemaeditor.controller.ProjectsViewController; import org.eclipse.jface.viewers.DecoratingLabelProvider; import org.eclipse.jface.viewers.TableViewer; import org.eclipse.swt.SWT; import org.eclipse.swt.widgets.Composite; import org.eclipse.ui.PlatformUI; import org.eclipse.ui.part.ViewPart; /** * This class represents the ProjectsView. * It is used to display the projects the user has created. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class ProjectsView extends ViewPart { /** The ID of the View */ public static final String ID = PluginConstants.VIEW_PROJECTS_VIEW_ID; /** The viewer */ private TableViewer tableViewer; /** * {@inheritDoc} */ public void createPartControl( Composite parent ) { // Help Context for Dynamic Help PlatformUI.getWorkbench().getHelpSystem().setHelp( parent, PluginConstants.PLUGIN_ID + "." + "projects_view" ); //$NON-NLS-1$ //$NON-NLS-2$ initViewer( parent ); // Adding the controller new ProjectsViewController( this ); } /** * Initializes the Viewer */ private void initViewer( Composite parent ) { tableViewer = new TableViewer( parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER ); tableViewer.setContentProvider( new ProjectsViewContentProvider( tableViewer ) ); tableViewer.setLabelProvider( new DecoratingLabelProvider( new ProjectsViewLabelProvider(), Activator .getDefault().getWorkbench().getDecoratorManager().getLabelDecorator() ) ); } /** * {@inheritDoc} */ public void setFocus() { tableViewer.getTable().setFocus(); } /** * Gets the TableViewer. * * @return * the TableViewer */ public TableViewer getViewer() { return tableViewer; } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/views/ProjectsViewContentProvider.java
plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/views/ProjectsViewContentProvider.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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.apache.directory.studio.schemaeditor.view.views; import java.util.ArrayList; import java.util.Collections; import java.util.List; import org.apache.directory.studio.schemaeditor.Activator; import org.apache.directory.studio.schemaeditor.model.Project; import org.apache.directory.studio.schemaeditor.view.wrappers.ProjectSorter; import org.apache.directory.studio.schemaeditor.view.wrappers.ProjectWrapper; import org.apache.directory.studio.schemaeditor.view.wrappers.ProjectsViewRoot; import org.apache.directory.studio.schemaeditor.view.wrappers.TreeNode; import org.eclipse.jface.viewers.IStructuredContentProvider; import org.eclipse.jface.viewers.ITreeContentProvider; import org.eclipse.jface.viewers.TableViewer; import org.eclipse.jface.viewers.Viewer; /** * This class implements the ContentProvider for the ProblemsView. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class ProjectsViewContentProvider implements IStructuredContentProvider, ITreeContentProvider { /** The viewer */ private TableViewer tableViewer; /** The Sorter */ private ProjectSorter projectSorter; /** * Creates a new instance of ProjectsViewContentProvider. * * @param tableViewer * the TableViewer */ public ProjectsViewContentProvider( TableViewer tableViewer ) { this.tableViewer = tableViewer; projectSorter = new ProjectSorter(); } /** * {@inheritDoc} */ public Object[] getElements( Object inputElement ) { return getChildren( inputElement ); } /** * {@inheritDoc} */ public void dispose() { // Nothing to do. } /** * {@inheritDoc} */ public void inputChanged( Viewer viewer, Object oldInput, Object newInput ) { // Nothing to do. } /** * {@inheritDoc} */ public Object[] getChildren( Object parentElement ) { List<TreeNode> children = new ArrayList<TreeNode>(); if ( parentElement instanceof ProjectsViewRoot ) { ProjectsViewRoot projectsViewRoot = ( ProjectsViewRoot ) parentElement; if ( !projectsViewRoot.hasChildren() ) { for ( Project project : Activator.getDefault().getProjectsHandler().getProjects() ) { projectsViewRoot.addChild( new ProjectWrapper( project, tableViewer ) ); } } children = projectsViewRoot.getChildren(); // Sorting Children Collections.sort( children, projectSorter ); } return children.toArray(); } /** * {@inheritDoc} */ public Object getParent( Object element ) { if ( element instanceof TreeNode ) { return ( ( TreeNode ) element ).getParent(); } // Default return null; } /** * {@inheritDoc} */ public boolean hasChildren( Object element ) { if ( element instanceof TreeNode ) { return ( ( TreeNode ) element ).hasChildren(); } // Default return false; } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/views/SchemaViewContentProvider.java
plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/views/SchemaViewContentProvider.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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.apache.directory.studio.schemaeditor.view.views; import java.util.ArrayList; import java.util.Collections; import java.util.List; import org.apache.commons.collections4.ListValuedMap; import org.apache.commons.collections4.multimap.ArrayListValuedHashMap; import org.apache.directory.api.ldap.model.schema.AttributeType; import org.apache.directory.api.ldap.model.schema.ObjectClass; import org.apache.directory.studio.schemaeditor.Activator; import org.apache.directory.studio.schemaeditor.PluginConstants; import org.apache.directory.studio.schemaeditor.controller.SchemaHandler; import org.apache.directory.studio.schemaeditor.model.Schema; import org.apache.directory.studio.schemaeditor.model.hierarchy.HierarchyManager; import org.apache.directory.studio.schemaeditor.view.wrappers.AttributeTypeWrapper; import org.apache.directory.studio.schemaeditor.view.wrappers.FirstNameSorter; import org.apache.directory.studio.schemaeditor.view.wrappers.Folder; import org.apache.directory.studio.schemaeditor.view.wrappers.Folder.FolderType; import org.apache.directory.studio.schemaeditor.view.wrappers.ObjectClassWrapper; import org.apache.directory.studio.schemaeditor.view.wrappers.OidSorter; import org.apache.directory.studio.schemaeditor.view.wrappers.SchemaSorter; import org.apache.directory.studio.schemaeditor.view.wrappers.SchemaViewRoot; import org.apache.directory.studio.schemaeditor.view.wrappers.SchemaWrapper; import org.apache.directory.studio.schemaeditor.view.wrappers.TreeNode; import org.eclipse.jface.preference.IPreferenceStore; import org.eclipse.jface.viewers.IStructuredContentProvider; import org.eclipse.jface.viewers.ITreeContentProvider; import org.eclipse.jface.viewers.Viewer; /** * This class implements the ContentProvider for the SchemaView. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class SchemaViewContentProvider implements IStructuredContentProvider, ITreeContentProvider { /** The preferences store */ private IPreferenceStore store; /** The FirstName Sorter */ private FirstNameSorter firstNameSorter; /** The OID Sorter */ private OidSorter oidSorter; /** The Schema Sorter */ private SchemaSorter schemaSorter; /** The RootWrapper */ private SchemaViewRoot root; /** The 'Elements To Wrappers' Map */ private ListValuedMap<Object, TreeNode> elementsToWrappersMap; private HierarchyManager hierarchyManager; /** * Creates a new instance of DifferencesWidgetSchemaContentProvider. */ public SchemaViewContentProvider() { store = Activator.getDefault().getPreferenceStore(); firstNameSorter = new FirstNameSorter(); oidSorter = new OidSorter(); schemaSorter = new SchemaSorter(); } /** * {@inheritDoc} */ public Object[] getElements( Object inputElement ) { return getChildren( inputElement ); } /** * {@inheritDoc} */ public void dispose() { // Nothing to do } /** * {@inheritDoc} */ public void inputChanged( Viewer viewer, Object oldInput, Object newInput ) { // Nothing to do } /** * {@inheritDoc} */ public Object[] getChildren( Object parentElement ) { List<TreeNode> children = new ArrayList<TreeNode>(); int presentation = store.getInt( PluginConstants.PREFS_SCHEMA_VIEW_SCHEMA_PRESENTATION ); int group = store.getInt( PluginConstants.PREFS_SCHEMA_VIEW_GROUPING ); int sortBy = store.getInt( PluginConstants.PREFS_SCHEMA_VIEW_SORTING_BY ); int sortOrder = store.getInt( PluginConstants.PREFS_SCHEMA_VIEW_SORTING_ORDER ); if ( parentElement instanceof SchemaViewRoot ) { root = ( SchemaViewRoot ) parentElement; if ( presentation == PluginConstants.PREFS_SCHEMA_VIEW_SCHEMA_PRESENTATION_FLAT ) { if ( root.getChildren().isEmpty() ) { elementsToWrappersMap = new ArrayListValuedHashMap<>(); SchemaHandler schemaHandler = Activator.getDefault().getSchemaHandler(); if ( schemaHandler != null ) { List<Schema> schemas = schemaHandler.getSchemas(); for ( Schema schema : schemas ) { addSchemaFlatPresentation( schema ); } } } children = root.getChildren(); Collections.sort( children, schemaSorter ); } else if ( presentation == PluginConstants.PREFS_SCHEMA_VIEW_SCHEMA_PRESENTATION_HIERARCHICAL ) { if ( root.getChildren().isEmpty() ) { elementsToWrappersMap = new ArrayListValuedHashMap<>(); hierarchyManager = new HierarchyManager(); if ( group == PluginConstants.PREFS_SCHEMA_VIEW_GROUPING_FOLDERS ) { Folder atFolder = new Folder( FolderType.ATTRIBUTE_TYPE, root ); Folder ocFolder = new Folder( FolderType.OBJECT_CLASS, root ); root.addChild( atFolder ); root.addChild( ocFolder ); List<Object> rootChildren = hierarchyManager.getChildren( hierarchyManager.getRootObject() ); if ( ( rootChildren != null ) && ( rootChildren.size() > 0 ) ) { for ( Object rootChild : rootChildren ) { TreeNode childNode = null; // Creating the wrapper if ( rootChild instanceof AttributeType ) { AttributeType at = ( AttributeType ) rootChild; childNode = new AttributeTypeWrapper( at, atFolder ); atFolder.addChild( childNode ); } else if ( rootChild instanceof ObjectClass ) { ObjectClass oc = ( ObjectClass ) rootChild; childNode = new ObjectClassWrapper( oc, ocFolder ); ocFolder.addChild( childNode ); } // Filling the 'Elements To Wrappers' Map elementsToWrappersMap.put( rootChild, childNode ); // Recursively creating the hierarchy for all children // of the root element. addHierarchyChildren( childNode, hierarchyManager.getChildren( rootChild ) ); } } } else if ( group == PluginConstants.PREFS_SCHEMA_VIEW_GROUPING_MIXED ) { addHierarchyChildren( root, hierarchyManager.getChildren( hierarchyManager.getRootObject() ) ); } } children = root.getChildren(); if ( group == PluginConstants.PREFS_SCHEMA_VIEW_GROUPING_MIXED ) { // Sort by if ( sortBy == PluginConstants.PREFS_SCHEMA_VIEW_SORTING_BY_FIRSTNAME ) { Collections.sort( children, firstNameSorter ); } else if ( sortBy == PluginConstants.PREFS_SCHEMA_VIEW_SORTING_BY_OID ) { Collections.sort( children, oidSorter ); } // Sort Order if ( sortOrder == PluginConstants.PREFS_SCHEMA_VIEW_SORTING_ORDER_DESCENDING ) { Collections.reverse( children ); } } } } else if ( parentElement instanceof Folder ) { children = ( ( TreeNode ) parentElement ).getChildren(); // Sort by if ( sortBy == PluginConstants.PREFS_SCHEMA_VIEW_SORTING_BY_FIRSTNAME ) { Collections.sort( children, firstNameSorter ); } else if ( sortBy == PluginConstants.PREFS_SCHEMA_VIEW_SORTING_BY_OID ) { Collections.sort( children, oidSorter ); } // Sort Order if ( sortOrder == PluginConstants.PREFS_SCHEMA_VIEW_SORTING_ORDER_DESCENDING ) { Collections.reverse( children ); } } else if ( ( parentElement instanceof AttributeTypeWrapper ) || ( parentElement instanceof ObjectClassWrapper ) ) { children = ( ( TreeNode ) parentElement ).getChildren(); // Sort by if ( sortBy == PluginConstants.PREFS_SCHEMA_VIEW_SORTING_BY_FIRSTNAME ) { Collections.sort( children, firstNameSorter ); } else if ( sortBy == PluginConstants.PREFS_SCHEMA_VIEW_SORTING_BY_OID ) { Collections.sort( children, oidSorter ); } // Sort Order if ( sortOrder == PluginConstants.PREFS_SCHEMA_VIEW_SORTING_ORDER_DESCENDING ) { Collections.reverse( children ); } } else if ( parentElement instanceof SchemaWrapper ) { children = ( ( TreeNode ) parentElement ).getChildren(); if ( group == PluginConstants.PREFS_SCHEMA_VIEW_GROUPING_MIXED ) { // Sort by if ( sortBy == PluginConstants.PREFS_SCHEMA_VIEW_SORTING_BY_FIRSTNAME ) { Collections.sort( children, firstNameSorter ); } else if ( sortBy == PluginConstants.PREFS_SCHEMA_VIEW_SORTING_BY_OID ) { Collections.sort( children, oidSorter ); } // Sort Order if ( sortOrder == PluginConstants.PREFS_SCHEMA_VIEW_SORTING_ORDER_DESCENDING ) { Collections.reverse( children ); } } } return children.toArray(); } /** * Converts the given children and adds them to the given node. * * @param node * the parent node. * @param children * the children */ private void addHierarchyChildren( TreeNode node, List<Object> children ) { if ( ( children != null ) && ( children.size() > 0 ) ) { for ( Object child : children ) { TreeNode childNode = null; if ( child instanceof AttributeType ) { AttributeType at = ( AttributeType ) child; childNode = new AttributeTypeWrapper( at, node ); node.addChild( childNode ); } else if ( child instanceof ObjectClass ) { ObjectClass oc = ( ObjectClass ) child; childNode = new ObjectClassWrapper( oc, node ); node.addChild( childNode ); } // Filling the 'Elements To Wrappers' Map elementsToWrappersMap.put( child, childNode ); // Recursively creating the hierarchy for all children // of the given element. addHierarchyChildren( childNode, hierarchyManager.getChildren( child ) ); } } } /** * {@inheritDoc} */ public Object getParent( Object element ) { if ( element instanceof TreeNode ) { return ( ( TreeNode ) element ).getParent(); } // Default return null; } /** * {@inheritDoc} */ public boolean hasChildren( Object element ) { if ( element instanceof TreeNode ) { return ( ( TreeNode ) element ).hasChildren(); } // Default return false; } /** * Gets the wrappers associated with the given object. * * @param o * the object * @return * the wrappers associated with the given object */ @SuppressWarnings("unchecked") public List<TreeNode> getWrappers( Object o ) { return ( List<TreeNode> ) elementsToWrappersMap.get( o ); } /** * Gets the wrapper associated with the given object. * * @param o * the object * @return * the wrapper associated with the given object */ public TreeNode getWrapper( Object o ) { List<TreeNode> wrappers = getWrappers( o ); if ( ( wrappers != null ) && ( wrappers.size() > 0 ) ) { return wrappers.get( 0 ); } // Default return null; } /** * Gets the Root Element. * * @return * the Root Element */ public SchemaViewRoot getRoot() { return root; } /** * Adds the given <element, wrapper> association. * * @param element * the element * @param wrapper * the wrapper */ public void addElementToWrapper( Object element, TreeNode wrapper ) { elementsToWrappersMap.put( element, wrapper ); } /** * Removes the given <element, wrapper> association. * * @param element * the element * @param wrapper * the wrapper */ public void removeElementToWrapper( Object element, TreeNode wrapper ) { elementsToWrappersMap.removeMapping( element, wrapper ); } /** * Remove all <element, wrapper> association for the given element. * * @param element * the element */ public void removeElementToWrapper( Object element ) { elementsToWrappersMap.remove( element ); } /** * This method is called when an attribute type is added. * * @param at * the added attribute type */ public void attributeTypeAdded( AttributeType at ) { int presentation = store.getInt( PluginConstants.PREFS_SCHEMA_VIEW_SCHEMA_PRESENTATION ); if ( presentation == PluginConstants.PREFS_SCHEMA_VIEW_SCHEMA_PRESENTATION_FLAT ) { attributeTypeAddedFlatPresentation( at ); } else if ( presentation == PluginConstants.PREFS_SCHEMA_VIEW_SCHEMA_PRESENTATION_HIERARCHICAL ) { attributeTypeAddedHierarchicalPresentation( at ); } } /** * Updates the TreeNodes when an attribute type is added and the * presentation is set as 'Flat'. * * @param at * the added attribute type */ public void attributeTypeAddedFlatPresentation( AttributeType at ) { SchemaWrapper schemaWrapper = ( SchemaWrapper ) getWrapper( Activator.getDefault().getSchemaHandler() .getSchema( at.getSchemaName() ) ); if ( schemaWrapper != null ) { AttributeTypeWrapper atw = null; int group = store.getInt( PluginConstants.PREFS_SCHEMA_VIEW_GROUPING ); if ( group == PluginConstants.PREFS_SCHEMA_VIEW_GROUPING_FOLDERS ) { for ( TreeNode child : schemaWrapper.getChildren() ) { if ( ( ( Folder ) child ).getType() == FolderType.ATTRIBUTE_TYPE ) { atw = new AttributeTypeWrapper( at, child ); break; } } } else if ( group == PluginConstants.PREFS_SCHEMA_VIEW_GROUPING_MIXED ) { atw = new AttributeTypeWrapper( at, schemaWrapper ); } atw.getParent().addChild( atw ); elementsToWrappersMap.put( at, atw ); } } /** * Updates the TreeNodes when an attribute type is added and the * presentation is set as 'Hierarchical'. * * @param at * the added attribute type */ public void attributeTypeAddedHierarchicalPresentation( AttributeType at ) { hierarchyManager.attributeTypeAdded( at ); List<TreeNode> createdWrappers = new ArrayList<TreeNode>(); List<Object> parents = hierarchyManager.getParents( at ); if ( parents != null ) { for ( Object parent : parents ) { AttributeTypeWrapper parentATW = ( AttributeTypeWrapper ) getWrapper( parent ); AttributeTypeWrapper atw = null; if ( parentATW == null ) { int group = store.getInt( PluginConstants.PREFS_SCHEMA_VIEW_GROUPING ); if ( group == PluginConstants.PREFS_SCHEMA_VIEW_GROUPING_FOLDERS ) { for ( TreeNode child : root.getChildren() ) { if ( child instanceof Folder ) { Folder folder = ( Folder ) child; if ( folder.getType().equals( FolderType.ATTRIBUTE_TYPE ) ) { atw = new AttributeTypeWrapper( at, folder ); break; } } } } else if ( group == PluginConstants.PREFS_SCHEMA_VIEW_GROUPING_MIXED ) { atw = new AttributeTypeWrapper( at, root ); } } else { atw = new AttributeTypeWrapper( at, parentATW ); } atw.getParent().addChild( atw ); createdWrappers.add( atw ); elementsToWrappersMap.put( at, atw ); } } List<Object> children = hierarchyManager.getChildren( at ); if ( children != null ) { for ( Object child : children ) { AttributeTypeWrapper childATW = ( AttributeTypeWrapper ) getWrapper( child ); elementsToWrappersMap.remove( child ); childATW.getParent().removeChild( childATW ); for ( TreeNode createdWrapper : createdWrappers ) { AttributeTypeWrapper atw = new AttributeTypeWrapper( ( AttributeType ) child, createdWrapper ); atw.getParent().addChild( atw ); elementsToWrappersMap.put( child, atw ); } } } } /** * This method is called when an attribute type is modified. * * @param at * the modified attribute type */ public void attributeTypeModified( AttributeType at ) { int presentation = store.getInt( PluginConstants.PREFS_SCHEMA_VIEW_SCHEMA_PRESENTATION ); if ( presentation == PluginConstants.PREFS_SCHEMA_VIEW_SCHEMA_PRESENTATION_FLAT ) { attributeTypeModifiedFlatPresentation( at ); } else if ( presentation == PluginConstants.PREFS_SCHEMA_VIEW_SCHEMA_PRESENTATION_HIERARCHICAL ) { attributeTypeModifiedHierarchicalPresentation( at ); } } /** * Updates the TreeNodes when an attribute type is modified and the * presentation is set as 'Flat'. * * @param at * the modified attribute type */ public void attributeTypeModifiedFlatPresentation( AttributeType at ) { // Nothing to do } /** * Updates the TreeNodes when an attribute type is modified and the * presentation is set as 'Hierarchical'. * * @param at * the modified attribute type */ public void attributeTypeModifiedHierarchicalPresentation( AttributeType at ) { // Propagating the modification to the hierarchy manager hierarchyManager.attributeTypeModified( at ); // Removing the Wrappers List<TreeNode> wrappers = getWrappers( at ); if ( wrappers != null ) { for ( TreeNode wrapper : wrappers ) { wrapper.getParent().removeChild( wrapper ); } elementsToWrappersMap.remove( at ); } // Creating the wrapper List<Object> parents = hierarchyManager.getParents( at ); if ( parents != null ) { for ( Object parent : parents ) { AttributeTypeWrapper parentATW = ( AttributeTypeWrapper ) getWrapper( parent ); AttributeTypeWrapper atw = null; if ( parentATW == null ) { int group = store.getInt( PluginConstants.PREFS_SCHEMA_VIEW_GROUPING ); if ( group == PluginConstants.PREFS_SCHEMA_VIEW_GROUPING_FOLDERS ) { for ( TreeNode child : root.getChildren() ) { if ( child instanceof Folder ) { Folder folder = ( Folder ) child; if ( folder.getType().equals( FolderType.ATTRIBUTE_TYPE ) ) { atw = new AttributeTypeWrapper( at, folder ); break; } } } } else if ( group == PluginConstants.PREFS_SCHEMA_VIEW_GROUPING_MIXED ) { atw = new AttributeTypeWrapper( at, root ); } } else { atw = new AttributeTypeWrapper( at, parentATW ); } atw.getParent().addChild( atw ); elementsToWrappersMap.put( at, atw ); addHierarchyChildren( atw, hierarchyManager.getChildren( at ) ); } } } /** * This method is called when an attribute type is removed. * * @param at * the removed attribute type */ public void attributeTypeRemoved( AttributeType at ) { int presentation = store.getInt( PluginConstants.PREFS_SCHEMA_VIEW_SCHEMA_PRESENTATION ); if ( presentation == PluginConstants.PREFS_SCHEMA_VIEW_SCHEMA_PRESENTATION_FLAT ) { attributeTypeRemovedFlatPresentation( at ); } else if ( presentation == PluginConstants.PREFS_SCHEMA_VIEW_SCHEMA_PRESENTATION_HIERARCHICAL ) { attributeTypeRemovedHierarchicalPresentation( at ); } } /** * Updates the TreeNodes when an attribute type is removed and the * presentation is set as 'Flat'. * * @param at * the removed attribute type */ private void attributeTypeRemovedFlatPresentation( AttributeType at ) { AttributeTypeWrapper atw = ( AttributeTypeWrapper ) getWrapper( at ); if ( atw != null ) { atw.getParent().removeChild( atw ); elementsToWrappersMap.removeMapping( at, atw ); } } /** * Updates the TreeNodes when an attribute type is removed and the * presentation is set as 'Hierarchical'. * * @param at * the removed attribute type */ private void attributeTypeRemovedHierarchicalPresentation( AttributeType at ) { // Creating children nodes of the AT // and attaching them to the root List<Object> children = hierarchyManager.getChildren( at ); if ( children != null ) { for ( Object child : children ) { AttributeTypeWrapper atw = null; int group = store.getInt( PluginConstants.PREFS_SCHEMA_VIEW_GROUPING ); if ( group == PluginConstants.PREFS_SCHEMA_VIEW_GROUPING_FOLDERS ) { for ( TreeNode rootChild : root.getChildren() ) { if ( rootChild instanceof Folder ) { Folder folder = ( Folder ) rootChild; if ( folder.getType().equals( FolderType.ATTRIBUTE_TYPE ) ) { atw = new AttributeTypeWrapper( ( AttributeType ) child, folder ); break; } } } } else if ( group == PluginConstants.PREFS_SCHEMA_VIEW_GROUPING_MIXED ) { atw = new AttributeTypeWrapper( ( AttributeType ) child, root ); } atw.getParent().addChild( atw ); elementsToWrappersMap.put( child, atw ); } } // Removing the Wrappers List<TreeNode> wrappers = getWrappers( at ); if ( wrappers != null ) { for ( TreeNode wrapper : wrappers ) { wrapper.getParent().removeChild( wrapper ); removeRecursiveChildren( wrapper ); } elementsToWrappersMap.remove( at ); } // Propagating the removal to the hierarchy manager hierarchyManager.attributeTypeRemoved( at ); } /** * Recursively removes the children of the given wrapper. * * @param wrapper * the wrapper */ private void removeRecursiveChildren( TreeNode wrapper ) { for ( TreeNode child : wrapper.getChildren() ) { if ( child instanceof AttributeTypeWrapper ) { AttributeTypeWrapper atw = ( AttributeTypeWrapper ) child; elementsToWrappersMap.removeMapping( atw.getAttributeType(), child ); removeRecursiveChildren( atw ); } else if ( child instanceof ObjectClassWrapper ) { ObjectClassWrapper ocw = ( ObjectClassWrapper ) child; elementsToWrappersMap.removeMapping( ocw.getObjectClass(), child ); removeRecursiveChildren( ocw ); } else { removeRecursiveChildren( child ); } } } /** * This method is called when an object class is added. * * @param oc * the added object class */ public void objectClassAdded( ObjectClass oc ) { int presentation = store.getInt( PluginConstants.PREFS_SCHEMA_VIEW_SCHEMA_PRESENTATION ); if ( presentation == PluginConstants.PREFS_SCHEMA_VIEW_SCHEMA_PRESENTATION_FLAT ) { objectClassAddedFlatPresentation( oc ); } else if ( presentation == PluginConstants.PREFS_SCHEMA_VIEW_SCHEMA_PRESENTATION_HIERARCHICAL ) { objectClassAddedHierarchicalPresentation( oc ); } } /** * Updates the TreeNodes when an object class is added and the * presentation is set as 'Flat'. * * @param oc * the added object class */ public void objectClassAddedFlatPresentation( ObjectClass oc ) { SchemaWrapper schemaWrapper = ( SchemaWrapper ) getWrapper( Activator.getDefault().getSchemaHandler() .getSchema( oc.getSchemaName() ) ); if ( schemaWrapper != null ) { ObjectClassWrapper ocw = null; int group = store.getInt( PluginConstants.PREFS_SCHEMA_VIEW_GROUPING ); if ( group == PluginConstants.PREFS_SCHEMA_VIEW_GROUPING_FOLDERS ) { for ( TreeNode child : schemaWrapper.getChildren() ) { if ( ( ( Folder ) child ).getType() == FolderType.OBJECT_CLASS ) { ocw = new ObjectClassWrapper( oc, child ); break; } } } else if ( group == PluginConstants.PREFS_SCHEMA_VIEW_GROUPING_MIXED ) { ocw = new ObjectClassWrapper( oc, schemaWrapper ); } ocw.getParent().addChild( ocw ); elementsToWrappersMap.put( oc, ocw ); } } /** * Updates the TreeNodes when an object class is added and the * presentation is set as 'Hierarchical'. * * @param oc * the added object class */ public void objectClassAddedHierarchicalPresentation( ObjectClass oc ) { // Removing unattached nodes for "top" List<Object> ocChildren = new ArrayList<Object>(); List<Object> ocChildren2 = null; if ( "2.5.6.0".equals( oc.getOid() ) ) //$NON-NLS-1$ { ocChildren2 = hierarchyManager.getChildren( "2.5.6.0" ); //$NON-NLS-1$ if ( ocChildren2 != null ) { ocChildren.addAll( ocChildren2 ); } ocChildren2 = hierarchyManager.getChildren( "top" ); //$NON-NLS-1$ if ( ocChildren2 != null ) { ocChildren.addAll( ocChildren2 ); } } ocChildren2 = hierarchyManager.getChildren( oc ); if ( ocChildren2 != null ) { ocChildren.addAll( ocChildren2 ); } for ( Object ocChild : ocChildren ) { List<TreeNode> wrappers = getWrappers( ocChild ); if ( wrappers != null ) { for ( TreeNode wrapper : wrappers ) { int group = store.getInt( PluginConstants.PREFS_SCHEMA_VIEW_GROUPING ); if ( group == PluginConstants.PREFS_SCHEMA_VIEW_GROUPING_FOLDERS ) { if ( wrapper.getParent().getParent().equals( root ) ) { wrapper.getParent().removeChild( wrapper ); elementsToWrappersMap.removeMapping( oc, wrapper ); } } else if ( group == PluginConstants.PREFS_SCHEMA_VIEW_GROUPING_MIXED ) { if ( wrapper.getParent().equals( root ) ) { wrapper.getParent().removeChild( wrapper ); elementsToWrappersMap.removeMapping( oc, wrapper ); } } removeRecursiveChildren( wrapper ); } } } // Propagating the addition to the hierarchy manager hierarchyManager.objectClassAdded( oc ); List<TreeNode> createdWrappers = new ArrayList<TreeNode>(); List<Object> parents = hierarchyManager.getParents( oc ); if ( parents != null ) { for ( Object parent : parents ) { ObjectClassWrapper parentOCW = ( ObjectClassWrapper ) getWrapper( parent ); ObjectClassWrapper ocw = null; if ( parentOCW == null ) { int group = store.getInt( PluginConstants.PREFS_SCHEMA_VIEW_GROUPING );
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
true
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/views/SearchViewLabelProvider.java
plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/views/SearchViewLabelProvider.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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.apache.directory.studio.schemaeditor.view.views; import java.util.List; import org.apache.directory.api.ldap.model.schema.AttributeType; import org.apache.directory.api.ldap.model.schema.ObjectClass; import org.apache.directory.api.ldap.model.schema.SchemaObject; import org.apache.directory.studio.schemaeditor.Activator; import org.apache.directory.studio.schemaeditor.PluginConstants; import org.apache.directory.studio.schemaeditor.view.ViewUtils; import org.eclipse.jface.preference.IPreferenceStore; import org.eclipse.jface.viewers.LabelProvider; import org.eclipse.swt.graphics.Image; /** * This class implements the LabelProvider for the SearchView. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class SearchViewLabelProvider extends LabelProvider { /** The preferences store */ private IPreferenceStore store; /** * Creates a new instance of DifferencesWidgetSchemaLabelProvider. */ public SearchViewLabelProvider() { store = Activator.getDefault().getPreferenceStore(); } /** * {@inheritDoc} */ public String getText( Object element ) { String label = ""; //$NON-NLS-1$ int labelValue = store.getInt( PluginConstants.PREFS_SEARCH_VIEW_LABEL ); boolean abbreviate = store.getBoolean( PluginConstants.PREFS_SEARCH_VIEW_ABBREVIATE ); int abbreviateMaxLength = store.getInt( PluginConstants.PREFS_SEARCH_VIEW_ABBREVIATE_MAX_LENGTH ); boolean secondaryLabelDisplay = store.getBoolean( PluginConstants.PREFS_SEARCH_VIEW_SECONDARY_LABEL_DISPLAY ); int secondaryLabelValue = store.getInt( PluginConstants.PREFS_SEARCH_VIEW_SECONDARY_LABEL ); boolean secondaryLabelAbbreviate = store .getBoolean( PluginConstants.PREFS_SEARCH_VIEW_SECONDARY_LABEL_ABBREVIATE ); int secondaryLabelAbbreviateMaxLength = store .getInt( PluginConstants.PREFS_SEARCH_VIEW_SECONDARY_LABEL_ABBREVIATE_MAX_LENGTH ); boolean schemaLabelDisplay = store.getBoolean( PluginConstants.PREFS_SEARCH_VIEW_SCHEMA_LABEL_DISPLAY ); if ( element instanceof AttributeType ) { AttributeType at = ( AttributeType ) element; // Label if ( labelValue == PluginConstants.PREFS_SEARCH_VIEW_LABEL_FIRST_NAME ) { List<String> names = at.getNames(); if ( ( names != null ) && ( names.size() > 0 ) ) { label = names.get( 0 ); } else { label = Messages.getString( "SearchViewLabelProvider.None" ); //$NON-NLS-1$ } } else if ( labelValue == PluginConstants.PREFS_SEARCH_VIEW_LABEL_ALL_ALIASES ) { List<String> names = at.getNames(); if ( ( names != null ) && ( names.size() > 0 ) ) { label = ViewUtils.concateAliases( names ); } else { label = Messages.getString( "SearchViewLabelProvider.None" ); //$NON-NLS-1$ } } else if ( labelValue == PluginConstants.PREFS_SEARCH_VIEW_LABEL_OID ) { label = at.getOid(); } else // Default { List<String> names = at.getNames(); if ( ( names != null ) && ( names.size() > 0 ) ) { label = names.get( 0 ); } else { label = Messages.getString( "SearchViewLabelProvider.None" ); //$NON-NLS-1$ } } // Abbreviate if ( abbreviate && ( abbreviateMaxLength < label.length() ) ) { label = label.substring( 0, abbreviateMaxLength ) + "..."; //$NON-NLS-1$ } } else if ( element instanceof ObjectClass ) { ObjectClass oc = ( ObjectClass ) element; // Label if ( labelValue == PluginConstants.PREFS_SEARCH_VIEW_LABEL_FIRST_NAME ) { List<String> names = oc.getNames(); if ( ( names != null ) && ( names.size() > 0 ) ) { label = names.get( 0 ); } else { label = Messages.getString( "SearchViewLabelProvider.None" ); //$NON-NLS-1$ } } else if ( labelValue == PluginConstants.PREFS_SEARCH_VIEW_LABEL_ALL_ALIASES ) { List<String> names = oc.getNames(); if ( ( names != null ) && ( names.size() > 0 ) ) { label = ViewUtils.concateAliases( names ); } else { label = Messages.getString( "SearchViewLabelProvider.None" ); //$NON-NLS-1$ } } else if ( labelValue == PluginConstants.PREFS_SEARCH_VIEW_LABEL_OID ) { label = oc.getOid(); } else // Default { List<String> names = oc.getNames(); if ( ( names != null ) && ( names.size() > 0 ) ) { label = names.get( 0 ); } else { label = Messages.getString( "SearchViewLabelProvider.None" ); //$NON-NLS-1$ } } // Abbreviate if ( abbreviate && ( abbreviateMaxLength < label.length() ) ) { label = label.substring( 0, abbreviateMaxLength ) + "..."; //$NON-NLS-1$ } } // Secondary Label if ( secondaryLabelDisplay ) { String secondaryLabel = ""; //$NON-NLS-1$ if ( element instanceof AttributeType ) { AttributeType at = ( AttributeType ) element; if ( secondaryLabelValue == PluginConstants.PREFS_SEARCH_VIEW_LABEL_FIRST_NAME ) { List<String> names = at.getNames(); if ( ( names != null ) && ( names.size() > 0 ) ) { secondaryLabel = names.get( 0 ); } else { secondaryLabel = Messages.getString( "SearchViewLabelProvider.None" ); //$NON-NLS-1$ } } else if ( secondaryLabelValue == PluginConstants.PREFS_SEARCH_VIEW_LABEL_ALL_ALIASES ) { List<String> names = at.getNames(); if ( ( names != null ) && ( names.size() > 0 ) ) { secondaryLabel = ViewUtils.concateAliases( names ); } else { secondaryLabel = Messages.getString( "SearchViewLabelProvider.None" ); //$NON-NLS-1$ } } else if ( secondaryLabelValue == PluginConstants.PREFS_SEARCH_VIEW_LABEL_OID ) { secondaryLabel = at.getOid(); } } else if ( element instanceof ObjectClass ) { ObjectClass oc = ( ObjectClass ) element; if ( secondaryLabelValue == PluginConstants.PREFS_SEARCH_VIEW_LABEL_FIRST_NAME ) { List<String> names = oc.getNames(); if ( ( names != null ) && ( names.size() > 0 ) ) { secondaryLabel = names.get( 0 ); } else { secondaryLabel = Messages.getString( "SearchViewLabelProvider.None" ); //$NON-NLS-1$ } } else if ( secondaryLabelValue == PluginConstants.PREFS_SEARCH_VIEW_LABEL_ALL_ALIASES ) { List<String> names = oc.getNames(); if ( ( names != null ) && ( names.size() > 0 ) ) { secondaryLabel = ViewUtils.concateAliases( names ); } else { secondaryLabel = Messages.getString( "SearchViewLabelProvider.None" ); //$NON-NLS-1$ } } else if ( secondaryLabelValue == PluginConstants.PREFS_SEARCH_VIEW_LABEL_OID ) { secondaryLabel = oc.getOid(); } } if ( secondaryLabelAbbreviate && ( secondaryLabelAbbreviateMaxLength < secondaryLabel.length() ) ) { secondaryLabel = secondaryLabel.substring( 0, secondaryLabelAbbreviateMaxLength ) + "..."; //$NON-NLS-1$ } label += " [" + secondaryLabel + "]"; //$NON-NLS-1$ //$NON-NLS-2$ } // Schema Label if ( schemaLabelDisplay ) { if ( element instanceof SchemaObject ) { SchemaObject object = ( SchemaObject ) element; label += " " + Messages.getString( "SearchViewLabelProvider.FromSchema" ) + " \"" + object.getSchemaName() + "\""; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ } } return label; } /** * {@inheritDoc} */ public Image getImage( Object element ) { if ( element instanceof AttributeType ) { return Activator.getDefault().getImage( PluginConstants.IMG_ATTRIBUTE_TYPE ); } else if ( element instanceof ObjectClass ) { return Activator.getDefault().getImage( PluginConstants.IMG_OBJECT_CLASS ); } // Default return null; } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/views/SearchViewContentProvider.java
plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/views/SearchViewContentProvider.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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.apache.directory.studio.schemaeditor.view.views; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.List; import org.apache.directory.api.ldap.model.schema.AttributeType; import org.apache.directory.api.ldap.model.schema.ObjectClass; import org.apache.directory.api.ldap.model.schema.SchemaObject; import org.apache.directory.studio.schemaeditor.Activator; import org.apache.directory.studio.schemaeditor.PluginConstants; import org.apache.directory.studio.schemaeditor.view.wrappers.TreeNode; import org.eclipse.jface.preference.IPreferenceStore; import org.eclipse.jface.viewers.IStructuredContentProvider; import org.eclipse.jface.viewers.ITreeContentProvider; import org.eclipse.jface.viewers.Viewer; /** * This class implements the ContentProvider for the SchemaView. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class SearchViewContentProvider implements IStructuredContentProvider, ITreeContentProvider { /** The preferences store */ private IPreferenceStore store; /** The FirstName Sorter */ private Comparator<SchemaObject> firstNameSorter; /** The OID Sorter */ private Comparator<SchemaObject> oidSorter; /** * Creates a new instance of DifferencesWidgetSchemaContentProvider. */ public SearchViewContentProvider() { store = Activator.getDefault().getPreferenceStore(); firstNameSorter = new Comparator<SchemaObject>() { public int compare( SchemaObject o1, SchemaObject o2 ) { List<String> o1Names = null; List<String> o2Names = null; if ( ( o1 instanceof AttributeType ) && ( o2 instanceof AttributeType ) ) { AttributeType at1 = ( AttributeType ) o1; AttributeType at2 = ( AttributeType ) o2; o1Names = at1.getNames(); o2Names = at2.getNames(); } else if ( ( o1 instanceof ObjectClass ) && ( o2 instanceof ObjectClass ) ) { ObjectClass oc1 = ( ObjectClass ) o1; ObjectClass oc2 = ( ObjectClass ) o2; o1Names = oc1.getNames(); o2Names = oc2.getNames(); } else if ( ( o1 instanceof AttributeType ) && ( o2 instanceof ObjectClass ) ) { AttributeType at = ( AttributeType ) o1; ObjectClass oc = ( ObjectClass ) o2; o1Names = at.getNames(); o2Names = oc.getNames(); } else if ( ( o1 instanceof ObjectClass ) && ( o2 instanceof AttributeType ) ) { ObjectClass oc = ( ObjectClass ) o1; AttributeType at = ( AttributeType ) o2; o1Names = oc.getNames(); o2Names = at.getNames(); } // Comparing the First Name if ( ( o1Names != null ) && ( o2Names != null ) ) { if ( ( o1Names.size() > 0 ) && ( o2Names.size() > 0 ) ) { return o1Names.get( 0 ).compareToIgnoreCase( o2Names.get( 0 ) ); } else if ( ( o1Names.size() == 0 ) && ( o2Names.size() > 0 ) ) { return "".compareToIgnoreCase( o2Names.get( 0 ) ); //$NON-NLS-1$ } else if ( ( o1Names.size() > 0 ) && ( o2Names.size() == 0 ) ) { return o1Names.get( 0 ).compareToIgnoreCase( "" ); //$NON-NLS-1$ } } // Default return o1.toString().compareToIgnoreCase( o2.toString() ); } }; oidSorter = new Comparator<SchemaObject>() { public int compare( SchemaObject o1, SchemaObject o2 ) { if ( ( o1 instanceof AttributeType ) && ( o2 instanceof AttributeType ) ) { AttributeType at1 = ( AttributeType ) o1; AttributeType at2 = ( AttributeType ) o2; return at1.getOid().compareToIgnoreCase( at2.getOid() ); } else if ( ( o1 instanceof ObjectClass ) && ( o2 instanceof ObjectClass ) ) { ObjectClass oc1 = ( ObjectClass ) o1; ObjectClass oc2 = ( ObjectClass ) o2; return oc1.getOid().compareToIgnoreCase( oc2.getOid() ); } else if ( ( o1 instanceof AttributeType ) && ( o2 instanceof ObjectClass ) ) { AttributeType at = ( AttributeType ) o1; ObjectClass oc = ( ObjectClass ) o2; return at.getOid().compareToIgnoreCase( oc.getOid() ); } else if ( ( o1 instanceof ObjectClass ) && ( o2 instanceof AttributeType ) ) { ObjectClass oc = ( ObjectClass ) o1; AttributeType at = ( AttributeType ) o2; return oc.getOid().compareToIgnoreCase( at.getOid() ); } // Default return o1.toString().compareToIgnoreCase( o2.toString() ); } }; } /** * {@inheritDoc} */ public Object[] getElements( Object inputElement ) { return getChildren( inputElement ); } /** * {@inheritDoc} */ public void dispose() { // Nothing to do } /** * {@inheritDoc} */ public void inputChanged( Viewer viewer, Object oldInput, Object newInput ) { // Nothing to do } /** * {@inheritDoc} */ @SuppressWarnings("unchecked") public Object[] getChildren( Object parentElement ) { List<SchemaObject> children = new ArrayList<SchemaObject>(); int group = store.getInt( PluginConstants.PREFS_SEARCH_VIEW_GROUPING ); int sortBy = store.getInt( PluginConstants.PREFS_SEARCH_VIEW_SORTING_BY ); int sortOrder = store.getInt( PluginConstants.PREFS_SEARCH_VIEW_SORTING_ORDER ); if ( parentElement instanceof List ) { List<SchemaObject> searchResults = ( List<SchemaObject> ) parentElement; if ( group == PluginConstants.PREFS_SEARCH_VIEW_GROUPING_ATTRIBUTE_TYPES_FIRST ) { List<AttributeType> attributeTypes = new ArrayList<AttributeType>(); List<ObjectClass> objectClasses = new ArrayList<ObjectClass>(); for ( SchemaObject searchResult : searchResults ) { if ( searchResult instanceof AttributeType ) { attributeTypes.add( ( AttributeType ) searchResult ); } else if ( searchResult instanceof ObjectClass ) { objectClasses.add( ( ObjectClass ) searchResult ); } } // Sort by if ( sortBy == PluginConstants.PREFS_SEARCH_VIEW_SORTING_BY_FIRSTNAME ) { Collections.sort( attributeTypes, firstNameSorter ); Collections.sort( objectClasses, firstNameSorter ); } else if ( sortBy == PluginConstants.PREFS_SEARCH_VIEW_SORTING_BY_OID ) { Collections.sort( attributeTypes, oidSorter ); Collections.sort( objectClasses, oidSorter ); } // Sort Order if ( sortOrder == PluginConstants.PREFS_SEARCH_VIEW_SORTING_ORDER_DESCENDING ) { Collections.reverse( attributeTypes ); Collections.reverse( objectClasses ); } children.addAll( attributeTypes ); children.addAll( objectClasses ); } else if ( group == PluginConstants.PREFS_SEARCH_VIEW_GROUPING_OBJECT_CLASSES_FIRST ) { List<AttributeType> attributeTypes = new ArrayList<AttributeType>(); List<ObjectClass> objectClasses = new ArrayList<ObjectClass>(); for ( SchemaObject searchResult : searchResults ) { if ( searchResult instanceof AttributeType ) { attributeTypes.add( ( AttributeType ) searchResult ); } else if ( searchResult instanceof ObjectClass ) { objectClasses.add( ( ObjectClass ) searchResult ); } } // Sort by if ( sortBy == PluginConstants.PREFS_SEARCH_VIEW_SORTING_BY_FIRSTNAME ) { Collections.sort( attributeTypes, firstNameSorter ); Collections.sort( objectClasses, firstNameSorter ); } else if ( sortBy == PluginConstants.PREFS_SEARCH_VIEW_SORTING_BY_OID ) { Collections.sort( attributeTypes, oidSorter ); Collections.sort( objectClasses, oidSorter ); } // Sort Order if ( sortOrder == PluginConstants.PREFS_SEARCH_VIEW_SORTING_ORDER_DESCENDING ) { Collections.reverse( attributeTypes ); Collections.reverse( objectClasses ); } children.addAll( objectClasses ); children.addAll( attributeTypes ); } else if ( group == PluginConstants.PREFS_SEARCH_VIEW_GROUPING_MIXED ) { children.addAll( searchResults ); // Sort by if ( sortBy == PluginConstants.PREFS_SEARCH_VIEW_SORTING_BY_FIRSTNAME ) { Collections.sort( children, firstNameSorter ); } else if ( sortBy == PluginConstants.PREFS_SEARCH_VIEW_SORTING_BY_OID ) { Collections.sort( children, oidSorter ); } // Sort Order if ( sortOrder == PluginConstants.PREFS_SEARCH_VIEW_SORTING_ORDER_DESCENDING ) { Collections.reverse( children ); } } } return children.toArray(); } /** * {@inheritDoc} */ public Object getParent( Object element ) { if ( element instanceof TreeNode ) { return ( ( TreeNode ) element ).getParent(); } // Default return null; } /** * {@inheritDoc} */ public boolean hasChildren( Object element ) { if ( element instanceof TreeNode ) { return ( ( TreeNode ) element ).hasChildren(); } // Default return false; } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/views/HierarchyViewContentProvider.java
plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/views/HierarchyViewContentProvider.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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.apache.directory.studio.schemaeditor.view.views; import java.util.ArrayList; import java.util.List; import org.apache.directory.api.ldap.model.schema.AttributeType; import org.apache.directory.api.ldap.model.schema.ObjectClass; import org.apache.directory.studio.schemaeditor.Activator; import org.apache.directory.studio.schemaeditor.PluginConstants; import org.apache.directory.studio.schemaeditor.model.hierarchy.HierarchyManager; import org.apache.directory.studio.schemaeditor.view.wrappers.AttributeTypeWrapper; import org.apache.directory.studio.schemaeditor.view.wrappers.ObjectClassWrapper; import org.apache.directory.studio.schemaeditor.view.wrappers.TreeNode; import org.eclipse.jface.viewers.IStructuredContentProvider; import org.eclipse.jface.viewers.ITreeContentProvider; import org.eclipse.jface.viewers.Viewer; /** * This class implements the Content Provider for the Schemas View. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class HierarchyViewContentProvider implements IStructuredContentProvider, ITreeContentProvider { /** * {@inheritDoc} */ public Object[] getElements( Object inputElement ) { return getChildren( inputElement ); } /** * {@inheritDoc} */ public Object[] getChildren( Object parentElement ) { List<TreeNode> children = new ArrayList<TreeNode>(); if ( parentElement instanceof ObjectClass ) { ObjectClass oc = ( ObjectClass ) parentElement; children = createTypeHierarchyObjectClass( oc ); } else if ( parentElement instanceof AttributeType ) { AttributeType at = ( AttributeType ) parentElement; children = createTypeHierarchyAttributeType( at ); } else if ( parentElement instanceof TreeNode ) { children = ( ( TreeNode ) parentElement ).getChildren(); } return children.toArray(); } /** * Creates the Type Hierarchy for an object class. * * @param oc * the object class * @return * the Type Hierarchy for an object class */ private List<TreeNode> createTypeHierarchyObjectClass( ObjectClass oc ) { List<TreeNode> children = new ArrayList<TreeNode>(); HierarchyManager hierarchyManager = new HierarchyManager(); // Creating the wrapper of the object class ObjectClassWrapper ocw = new ObjectClassWrapper( oc ); int mode = Activator.getDefault().getDialogSettings().getInt( PluginConstants.PREFS_HIERARCHY_VIEW_MODE ); if ( mode == PluginConstants.PREFS_HIERARCHY_VIEW_MODE_TYPE ) { // Creating its children's wrappers createChildrenHierarchy( ocw, hierarchyManager.getChildren( oc ), hierarchyManager ); // Creating its parents' wrappers createParentHierarchy( hierarchyManager.getParents( oc ), children, ocw, hierarchyManager ); } else if ( mode == PluginConstants.PREFS_HIERARCHY_VIEW_MODE_SUPERTYPE ) { // Creating its parents' wrappers createParentHierarchy( hierarchyManager.getParents( oc ), children, ocw, hierarchyManager ); } else if ( mode == PluginConstants.PREFS_HIERARCHY_VIEW_MODE_SUBTYPE ) { // Creating its children's wrappers createChildrenHierarchy( ocw, hierarchyManager.getChildren( oc ), hierarchyManager ); children.add( ocw ); } return children; } /** * Creates the parent hierarchy. * * @param parents * the parents * @param children * the children * @param ocw * the object class wrapper * @param hierarchyManager * the hierarchy manager */ private void createParentHierarchy( List<Object> parents, List<TreeNode> children, ObjectClassWrapper ocw, HierarchyManager hierarchyManager ) { if ( parents != null ) { for ( Object parent : parents ) { if ( parent instanceof ObjectClass ) { ObjectClass parentOC = ( ObjectClass ) parent; ObjectClassWrapper duplicatedOCW = ( ObjectClassWrapper ) duplicateTreeNode( ocw ); ObjectClassWrapper ocw2 = new ObjectClassWrapper( parentOC ); duplicatedOCW.setParent( ocw2 ); ocw2.addChild( duplicatedOCW ); createParentHierarchy( hierarchyManager.getParents( parentOC ), children, ocw2, hierarchyManager ); } else { children.add( ocw ); } } } else { children.add( ocw ); } } /** * Duplicates the given node. * * @param node * the node * @return * a duplicate of the given node */ public TreeNode duplicateTreeNode( TreeNode node ) { if ( node != null ) { if ( node instanceof ObjectClassWrapper ) { ObjectClassWrapper ocNode = ( ObjectClassWrapper ) node; ObjectClassWrapper duplicatedOCNode = new ObjectClassWrapper( ocNode.getObjectClass(), ocNode .getParent() ); for ( TreeNode child : ocNode.getChildren() ) { TreeNode duplicatedChild = duplicateTreeNode( child ); if ( duplicatedChild != null ) { duplicatedOCNode.addChild( duplicatedChild ); } } return duplicatedOCNode; } } return null; } /** * Creates the Type Hierarchy for an attribute type. * * @param at * the attribute type * @return * the Type Hierarchy for an attribute type */ private List<TreeNode> createTypeHierarchyAttributeType( AttributeType at ) { List<TreeNode> children = new ArrayList<TreeNode>(); HierarchyManager hierarchyManager = new HierarchyManager(); int mode = Activator.getDefault().getDialogSettings().getInt( PluginConstants.PREFS_HIERARCHY_VIEW_MODE ); // Creating the wrapper of the attribute type AttributeTypeWrapper atw = new AttributeTypeWrapper( at ); if ( mode == PluginConstants.PREFS_HIERARCHY_VIEW_MODE_TYPE ) { // Creating the children's wrappers createChildrenHierarchy( atw, hierarchyManager.getChildren( at ), hierarchyManager ); // Creating its parents' wrappers List<Object> parents = hierarchyManager.getParents( at ); while ( ( parents != null ) && ( parents.size() == 1 ) ) { Object parent = parents.get( 0 ); if ( parent instanceof AttributeType ) { AttributeType parentAT = ( AttributeType ) parent; AttributeTypeWrapper atw2 = new AttributeTypeWrapper( parentAT ); atw.setParent( atw2 ); atw2.addChild( atw ); atw = atw2; parents = hierarchyManager.getParents( parentAT ); } else { break; } } children.add( atw ); } else if ( mode == PluginConstants.PREFS_HIERARCHY_VIEW_MODE_SUPERTYPE ) { // Creating its parents' wrappers List<Object> parents = hierarchyManager.getParents( at ); while ( ( parents != null ) && ( parents.size() == 1 ) ) { Object parent = parents.get( 0 ); if ( parent instanceof AttributeType ) { AttributeType parentAT = ( AttributeType ) parent; AttributeTypeWrapper atw2 = new AttributeTypeWrapper( parentAT ); atw.setParent( atw2 ); atw2.addChild( atw ); atw = atw2; parents = hierarchyManager.getParents( parentAT ); } else { break; } } children.add( atw ); } else if ( mode == PluginConstants.PREFS_HIERARCHY_VIEW_MODE_SUBTYPE ) { // Creating the children's wrappers createChildrenHierarchy( atw, hierarchyManager.getChildren( at ), hierarchyManager ); children.add( atw ); } return children; } /** * Create the children hierarchy * * @param node * the parent node. * @param children * the children */ private void createChildrenHierarchy( TreeNode node, List<Object> children, HierarchyManager hierarchyManager ) { if ( ( children != null ) && ( children.size() > 0 ) ) { for ( Object child : children ) { TreeNode childNode = null; if ( child instanceof AttributeType ) { AttributeType at = ( AttributeType ) child; childNode = new AttributeTypeWrapper( at, node ); node.addChild( childNode ); } else if ( child instanceof ObjectClass ) { ObjectClass oc = ( ObjectClass ) child; childNode = new ObjectClassWrapper( oc, node ); node.addChild( childNode ); } // Recursively creating the hierarchy for all children // of the given element. createChildrenHierarchy( childNode, hierarchyManager.getChildren( child ), hierarchyManager ); } } } /** * {@inheritDoc} */ public Object getParent( Object element ) { if ( element instanceof TreeNode ) { return ( ( TreeNode ) element ).getParent(); } // Default return null; } /** * {@inheritDoc} */ public boolean hasChildren( Object element ) { if ( element instanceof TreeNode ) { return true; } // Default return false; } /** * {@inheritDoc} */ public void dispose() { } /** * {@inheritDoc} */ public void inputChanged( Viewer viewer, Object oldInput, Object newInput ) { } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/views/ProblemsViewContentProvider.java
plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/views/ProblemsViewContentProvider.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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.apache.directory.studio.schemaeditor.view.views; import java.util.ArrayList; import java.util.List; import org.apache.directory.api.ldap.model.exception.LdapSchemaException; import org.apache.directory.studio.schemaeditor.Activator; import org.apache.directory.studio.schemaeditor.model.schemachecker.SchemaChecker; import org.apache.directory.studio.schemaeditor.model.schemachecker.SchemaWarning; import org.apache.directory.studio.schemaeditor.view.wrappers.Folder; import org.apache.directory.studio.schemaeditor.view.wrappers.Folder.FolderType; import org.apache.directory.studio.schemaeditor.view.wrappers.ProblemsViewRoot; import org.apache.directory.studio.schemaeditor.view.wrappers.SchemaErrorWrapper; import org.apache.directory.studio.schemaeditor.view.wrappers.SchemaWarningWrapper; import org.apache.directory.studio.schemaeditor.view.wrappers.TreeNode; import org.eclipse.jface.viewers.IStructuredContentProvider; import org.eclipse.jface.viewers.ITreeContentProvider; import org.eclipse.jface.viewers.Viewer; /** * This class implements the ContentProvider for the ProblemsView. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class ProblemsViewContentProvider implements IStructuredContentProvider, ITreeContentProvider { /** * {@inheritDoc} */ public Object[] getElements( Object inputElement ) { return getChildren( inputElement ); } /** * {@inheritDoc} */ public void dispose() { // Nothing to do. } /** * {@inheritDoc} */ public void inputChanged( Viewer viewer, Object oldInput, Object newInput ) { // Nothing to do. } /** * {@inheritDoc} */ public Object[] getChildren( Object parentElement ) { List<TreeNode> children = null; if ( parentElement instanceof ProblemsViewRoot ) { ProblemsViewRoot root = ( ProblemsViewRoot ) parentElement; if ( root.getChildren().isEmpty() ) { SchemaChecker schemaChecker = Activator.getDefault().getSchemaChecker(); if ( schemaChecker != null ) { List<Throwable> errors = schemaChecker.getErrors(); if ( !( errors.size() == 0 ) ) { Folder errorsFolder = new Folder( FolderType.ERROR, root ); root.addChild( errorsFolder ); for ( Throwable error : errors ) { if ( error instanceof LdapSchemaException ) { errorsFolder.addChild( new SchemaErrorWrapper( ( LdapSchemaException ) error, errorsFolder ) ); } } } SchemaWarning[] warnings = schemaChecker.getWarnings().toArray( new SchemaWarning[0] ); if ( !( warnings.length == 0 ) ) { Folder warningsFolder = new Folder( FolderType.WARNING, root ); root.addChild( warningsFolder ); for ( SchemaWarning warning : warnings ) { warningsFolder.addChild( new SchemaWarningWrapper( warning, warningsFolder ) ); } } } } children = root.getChildren(); } else if ( parentElement instanceof Folder ) { Folder folder = ( Folder ) parentElement; children = folder.getChildren(); } else if ( parentElement instanceof SchemaErrorWrapper ) { children = new ArrayList<TreeNode>(); } else if ( parentElement instanceof SchemaWarningWrapper ) { children = new ArrayList<TreeNode>(); } return children.toArray(); } /** * {@inheritDoc} */ public Object getParent( Object element ) { if ( element instanceof TreeNode ) { return ( ( TreeNode ) element ).getParent(); } // Default return null; } /** * {@inheritDoc} */ public boolean hasChildren( Object element ) { if ( element instanceof TreeNode ) { return ( ( TreeNode ) element ).hasChildren(); } // Default return false; } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/views/SchemaViewSortingDialog.java
plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/views/SchemaViewSortingDialog.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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.apache.directory.studio.schemaeditor.view.views; import org.apache.directory.studio.schemaeditor.Activator; import org.apache.directory.studio.schemaeditor.PluginConstants; import org.eclipse.jface.dialogs.Dialog; import org.eclipse.jface.dialogs.IDialogConstants; import org.eclipse.jface.preference.IPreferenceStore; import org.eclipse.swt.SWT; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Combo; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Group; import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Shell; /** * This class implements the SchemaView Sorting Dialog. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class SchemaViewSortingDialog extends Dialog { // UI Fields private Button inFoldersButton; private Button mixedButton; private Combo sortingCombo; private Button ascendingButton; private Button descendingButton; /** * Creates a new instance of SchemasViewSorterDialog. * * @param parentShell * the parent shell */ public SchemaViewSortingDialog( Shell parentShell ) { super( parentShell ); } /** * {@inheritDoc} */ protected void configureShell( Shell newShell ) { super.configureShell( newShell ); newShell.setText( Messages.getString( "SchemaViewSortingDialog.ViewSorting" ) ); //$NON-NLS-1$ } /** * {@inheritDoc} */ protected Control createDialogArea( Composite parent ) { Composite composite = ( Composite ) super.createDialogArea( parent ); composite.setLayoutData( new GridData( SWT.FILL, SWT.FILL, true, true ) ); // Grouping Group Group groupingGroup = new Group( composite, SWT.NONE ); groupingGroup.setLayoutData( new GridData( SWT.FILL, SWT.FILL, true, true ) ); groupingGroup.setText( Messages.getString( "SchemaViewSortingDialog.Grouping" ) ); //$NON-NLS-1$ groupingGroup.setLayout( new GridLayout() ); // Attribute Types first Button inFoldersButton = new Button( groupingGroup, SWT.RADIO ); inFoldersButton.setText( Messages.getString( "SchemaViewSortingDialog.GroupTypesAndClasses" ) ); //$NON-NLS-1$ inFoldersButton.setEnabled( true ); // Mixed Button mixedButton = new Button( groupingGroup, SWT.RADIO ); mixedButton.setText( Messages.getString( "SchemaViewSortingDialog.Mixed" ) ); //$NON-NLS-1$ mixedButton.setEnabled( true ); // Sorting Group Group sortingGroup = new Group( composite, SWT.NONE ); sortingGroup.setLayoutData( new GridData( SWT.FILL, SWT.FILL, true, true ) ); sortingGroup.setText( Messages.getString( "SchemaViewSortingDialog.Sorting" ) ); //$NON-NLS-1$ sortingGroup.setLayout( new GridLayout() ); Composite sortingGroupComposite = new Composite( sortingGroup, SWT.NONE ); GridLayout gl = new GridLayout( 4, false ); gl.marginHeight = gl.marginWidth = 0; sortingGroupComposite.setLayout( gl ); sortingGroupComposite.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) ); // Sort by Label Label sortByLabel = new Label( sortingGroupComposite, SWT.NONE ); sortByLabel.setText( Messages.getString( "SchemaViewSortingDialog.SortBy" ) ); //$NON-NLS-1$ // Sorting Combo sortingCombo = new Combo( sortingGroupComposite, SWT.DROP_DOWN | SWT.READ_ONLY | SWT.BORDER ); sortingCombo.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) ); sortingCombo .setItems( new String[] { Messages.getString( "SchemaViewSortingDialog.FirstName" ), Messages.getString( "SchemaViewSortingDialog.OID" ) } ); //$NON-NLS-1$ //$NON-NLS-2$ sortingCombo.setEnabled( true ); // Ascending Button ascendingButton = new Button( sortingGroupComposite, SWT.RADIO ); ascendingButton.setText( Messages.getString( "SchemaViewSortingDialog.Ascending" ) ); //$NON-NLS-1$ ascendingButton.setEnabled( true ); // Descending Button descendingButton = new Button( sortingGroupComposite, SWT.RADIO ); descendingButton.setText( Messages.getString( "SchemaViewSortingDialog.Descending" ) ); //$NON-NLS-1$ descendingButton.setEnabled( true ); initFieldsFromPreferences(); applyDialogFont( composite ); return composite; } /** * Initializes the fields for the stored preferences. */ private void initFieldsFromPreferences() { IPreferenceStore store = Activator.getDefault().getPreferenceStore(); int grouping = store.getInt( PluginConstants.PREFS_SCHEMA_VIEW_GROUPING ); if ( grouping == PluginConstants.PREFS_SCHEMA_VIEW_GROUPING_FOLDERS ) { inFoldersButton.setSelection( true ); } else if ( grouping == PluginConstants.PREFS_SCHEMA_VIEW_GROUPING_MIXED ) { mixedButton.setSelection( true ); } int sortingBy = store.getInt( PluginConstants.PREFS_SCHEMA_VIEW_SORTING_BY ); if ( sortingBy == PluginConstants.PREFS_SCHEMA_VIEW_SORTING_BY_FIRSTNAME ) { sortingCombo.select( 0 ); } else if ( sortingBy == PluginConstants.PREFS_SCHEMA_VIEW_SORTING_BY_OID ) { sortingCombo.select( 1 ); } int sortingOrder = store.getInt( PluginConstants.PREFS_SCHEMA_VIEW_SORTING_ORDER ); if ( sortingOrder == PluginConstants.PREFS_SCHEMA_VIEW_SORTING_ORDER_ASCENDING ) { ascendingButton.setSelection( true ); } else if ( sortingOrder == PluginConstants.PREFS_SCHEMA_VIEW_SORTING_ORDER_DESCENDING ) { descendingButton.setSelection( true ); } } /** * {@inheritDoc} */ protected void buttonPressed( int buttonId ) { if ( buttonId == IDialogConstants.OK_ID ) { IPreferenceStore store = Activator.getDefault().getPreferenceStore(); if ( ( inFoldersButton.getSelection() ) && ( !mixedButton.getSelection() ) ) { store.setValue( PluginConstants.PREFS_SCHEMA_VIEW_GROUPING, PluginConstants.PREFS_SCHEMA_VIEW_GROUPING_FOLDERS ); } else if ( ( !inFoldersButton.getSelection() ) && ( mixedButton.getSelection() ) ) { store.setValue( PluginConstants.PREFS_SCHEMA_VIEW_GROUPING, PluginConstants.PREFS_SCHEMA_VIEW_GROUPING_MIXED ); } if ( sortingCombo.getItem( sortingCombo.getSelectionIndex() ).equals( Messages.getString( "SchemaViewSortingDialog.FirstName" ) ) ) //$NON-NLS-1$ { store.setValue( PluginConstants.PREFS_SCHEMA_VIEW_SORTING_BY, PluginConstants.PREFS_SCHEMA_VIEW_SORTING_BY_FIRSTNAME ); } else if ( sortingCombo.getItem( sortingCombo.getSelectionIndex() ).equals( Messages.getString( "SchemaViewSortingDialog.OID" ) ) ) //$NON-NLS-1$ { store.setValue( PluginConstants.PREFS_SCHEMA_VIEW_SORTING_BY, PluginConstants.PREFS_SCHEMA_VIEW_SORTING_BY_OID ); } if ( ascendingButton.getSelection() && !descendingButton.getSelection() ) { store.setValue( PluginConstants.PREFS_SCHEMA_VIEW_SORTING_ORDER, PluginConstants.PREFS_SCHEMA_VIEW_SORTING_ORDER_ASCENDING ); } else if ( !ascendingButton.getSelection() && descendingButton.getSelection() ) { store.setValue( PluginConstants.PREFS_SCHEMA_VIEW_SORTING_ORDER, PluginConstants.PREFS_SCHEMA_VIEW_SORTING_ORDER_DESCENDING ); } } super.buttonPressed( buttonId ); } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/wrappers/SchemaViewRoot.java
plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/wrappers/SchemaViewRoot.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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.apache.directory.studio.schemaeditor.view.wrappers; /** * This wrapper is used as root in the Schema View. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class SchemaViewRoot extends AbstractTreeNode { /** * Creates a new instance of SchemaViewRoot. */ public SchemaViewRoot() { super( null ); } /** * {@inheritDoc} */ public boolean equals( Object obj ) { if ( obj instanceof SchemaViewRoot ) { return this == obj; } return false; } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/wrappers/FirstNameSorter.java
plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/wrappers/FirstNameSorter.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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.apache.directory.studio.schemaeditor.view.wrappers; import java.util.Comparator; import java.util.List; import org.apache.directory.api.ldap.model.schema.AttributeType; import org.apache.directory.api.ldap.model.schema.ObjectClass; /** * This class is used to compare and sort ascending two TreeNode. */ public class FirstNameSorter implements Comparator<TreeNode> { /** * {@inheritDoc} */ public int compare( TreeNode o1, TreeNode o2 ) { List<String> o1Names = null; List<String> o2Names = null; if ( ( o1 instanceof AttributeTypeWrapper ) && ( o2 instanceof AttributeTypeWrapper ) ) { AttributeType at1 = ( ( AttributeTypeWrapper ) o1 ).getAttributeType(); AttributeType at2 = ( ( AttributeTypeWrapper ) o2 ).getAttributeType(); o1Names = at1.getNames(); o2Names = at2.getNames(); } else if ( ( o1 instanceof ObjectClassWrapper ) && ( o2 instanceof ObjectClassWrapper ) ) { ObjectClass oc1 = ( ( ObjectClassWrapper ) o1 ).getObjectClass(); ObjectClass oc2 = ( ( ObjectClassWrapper ) o2 ).getObjectClass(); o1Names = oc1.getNames(); o2Names = oc2.getNames(); } else if ( ( o1 instanceof AttributeTypeWrapper ) && ( o2 instanceof ObjectClassWrapper ) ) { AttributeType at = ( ( AttributeTypeWrapper ) o1 ).getAttributeType(); ObjectClass oc = ( ( ObjectClassWrapper ) o2 ).getObjectClass(); o1Names = at.getNames(); o2Names = oc.getNames(); } else if ( ( o1 instanceof ObjectClassWrapper ) && ( o2 instanceof AttributeTypeWrapper ) ) { ObjectClass oc = ( ( ObjectClassWrapper ) o1 ).getObjectClass(); AttributeType at = ( ( AttributeTypeWrapper ) o2 ).getAttributeType(); o1Names = oc.getNames(); o2Names = at.getNames(); } // Comparing the First Name if ( ( o1Names != null ) && ( o2Names != null ) ) { if ( ( o1Names.size() > 0 ) && ( o2Names.size() > 0 ) ) { return o1Names.get( 0 ).compareToIgnoreCase( o2Names.get( 0 ) ); } else if ( ( o1Names.size() == 0 ) && ( o2Names.size() > 0 ) ) { return "".compareToIgnoreCase( o2Names.get( 0 ) ); //$NON-NLS-1$ } else if ( ( o1Names.size() > 0 ) && ( o2Names.size() == 0 ) ) { return o1Names.get( 0 ).compareToIgnoreCase( "" ); //$NON-NLS-1$ } } // Default return o1.toString().compareToIgnoreCase( o2.toString() ); } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/wrappers/SchemaSorter.java
plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/wrappers/SchemaSorter.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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.apache.directory.studio.schemaeditor.view.wrappers; import java.util.Comparator; import org.apache.directory.studio.schemaeditor.model.Schema; /** * This class is used to compare and sort ascending two Schemas */ public class SchemaSorter implements Comparator<TreeNode> { /** * {@inheritDoc} */ public int compare( TreeNode o1, TreeNode o2 ) { if ( ( o1 instanceof SchemaWrapper ) && ( o2 instanceof SchemaWrapper ) ) { Schema s1 = ( ( SchemaWrapper ) o1 ).getSchema(); Schema s2 = ( ( SchemaWrapper ) o2 ).getSchema(); if ( ( s1 != null ) && ( s2 != null ) ) { return s1.getSchemaName().compareToIgnoreCase( s2.getSchemaName() ); } } // Default return o1.toString().compareToIgnoreCase( o2.toString() ); } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/wrappers/ProjectWrapper.java
plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/wrappers/ProjectWrapper.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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.apache.directory.studio.schemaeditor.view.wrappers; import org.apache.directory.studio.schemaeditor.Activator; import org.apache.directory.studio.schemaeditor.controller.ProjectListener; import org.apache.directory.studio.schemaeditor.model.Project; import org.eclipse.jface.viewers.TableViewer; /** * This class is used to wrap a Project in a TreeViewer. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class ProjectWrapper extends AbstractTreeNode { /** The wrapped Project */ private Project project; /** The TableViewer */ private TableViewer viewer; /** * Creates a new instance of ProjectWrapper. * * @param project * the wrapped Project */ public ProjectWrapper( Project project, final TableViewer tableViewer ) { super( null ); this.project = project; this.viewer = tableViewer; Activator.getDefault().getProjectsHandler().addListener( project, new ProjectListener() { public void projectRenamed() { viewer.refresh(); } } ); } /** * Gets the wrapped Project. * * @return * the wrapped Project */ public Project getProject() { return project; } /** * {@inheritDoc} */ public boolean hasChildren() { return false; } /** * {@inheritDoc} */ public boolean equals( Object obj ) { if ( obj instanceof ProjectWrapper ) { ProjectWrapper projectWrapper = ( ProjectWrapper ) obj; if ( ( project != null ) && ( !project.equals( projectWrapper.getProject() ) ) ) { return false; } return true; } return false; } /** * {@inheritDoc} */ public int hashCode() { int result = super.hashCode(); if ( project != null ) { result = 37 * result + project.hashCode(); } return result; } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/wrappers/ProjectSorter.java
plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/wrappers/ProjectSorter.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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.apache.directory.studio.schemaeditor.view.wrappers; import java.util.Comparator; /** * This class is used to compare and sort ascending two TreeNode */ public class ProjectSorter implements Comparator<TreeNode> { /** * {@inheritDoc} */ public int compare( TreeNode tn1, TreeNode tn2 ) { if ( ( tn1 instanceof ProjectWrapper ) && ( tn2 instanceof ProjectWrapper ) ) { ProjectWrapper pw1 = ( ProjectWrapper ) tn1; ProjectWrapper pw2 = ( ProjectWrapper ) tn2; return pw1.getProject().getName().compareToIgnoreCase( pw2.getProject().getName() ); } // Default return 0; } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/wrappers/ProblemsViewRoot.java
plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/wrappers/ProblemsViewRoot.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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.apache.directory.studio.schemaeditor.view.wrappers; /** * This wrapper is used as root in the Problems View. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class ProblemsViewRoot extends AbstractTreeNode { /** * Creates a new instance of ProblemsViewRoot. */ public ProblemsViewRoot() { super( null ); } /** * {@inheritDoc} */ public boolean equals( Object obj ) { if ( obj instanceof ProblemsViewRoot ) { return this == obj; } return false; } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/wrappers/ObjectClassWrapper.java
plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/wrappers/ObjectClassWrapper.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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.apache.directory.studio.schemaeditor.view.wrappers; import org.apache.directory.api.ldap.model.schema.ObjectClass; import org.eclipse.osgi.util.NLS; /** * This class is used to wrap an ObjectClass in a TreeViewer. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class ObjectClassWrapper extends AbstractTreeNode { /** The wrapped ObjectClass */ private ObjectClass objectClass; /** * Creates a new instance of ObjectClassWrapper. * * @param oc * the wrapped ObjectClass */ public ObjectClassWrapper( ObjectClass oc ) { super( null ); objectClass = oc; } /** * Creates a new instance of ObjectClassWrapper. * * @param at * the wrapped ObjectClass * @param parent * the parent TreeNode */ public ObjectClassWrapper( ObjectClass oc, TreeNode parent ) { super( parent ); objectClass = oc; } /** * Gets the wrapped ObjectClass. * * @return * the wrapped ObjectClass */ public ObjectClass getObjectClass() { return objectClass; } /** * {@inheritDoc} */ public boolean equals( Object obj ) { if ( obj instanceof ObjectClassWrapper ) { if ( super.equals( obj ) ) { ObjectClassWrapper ocw = ( ObjectClassWrapper ) obj; if ( ( objectClass != null ) && ( !objectClass.equals( ocw.getObjectClass() ) ) ) { return false; } return true; } } // Default return false; } /** * {@inheritDoc} */ public int hashCode() { int result = super.hashCode(); if ( objectClass != null ) { result = 37 * result + objectClass.hashCode(); } return result; } /** * {@inheritDoc} */ public String toString() { return NLS.bind( Messages.getString( "ObjectClassWrapper.ObjectWrapperClass" ), new Object[] { objectClass, fParent } ); //$NON-NLS-1$ } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/wrappers/Messages.java
plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/wrappers/Messages.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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.apache.directory.studio.schemaeditor.view.wrappers; import java.util.MissingResourceException; import java.util.ResourceBundle; /** * This class get messages from the resources file. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class Messages { /** The resource name */ private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle.getBundle( Messages.class.getPackage().getName() + ".messages" ); /** * Get back a message from the resource file given a key * * @param key The key associated with the message * @return The found message */ public static String getString( String key ) { try { return RESOURCE_BUNDLE.getString( key ); } catch ( MissingResourceException e ) { return '!' + key + '!'; } } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/wrappers/TreeNode.java
plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/wrappers/TreeNode.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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.apache.directory.studio.schemaeditor.view.wrappers; import java.util.Collection; import java.util.List; /** * This interface defines an element that can be used in a TreeViewer. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public interface TreeNode { /** * Gets the children of the element. * * @return * the children of the element */ List<TreeNode> getChildren(); /** * Returns true if the element has children. * * @return * true if the element has children */ boolean hasChildren(); /** * Gets the parent of the element. * * @return * the parent of the element */ TreeNode getParent(); /** * Sets the parent of the element. * * @param node * the parent of the element */ void setParent( TreeNode parent ); /** * Adds a node to the element. * * @param node * the node to add */ void addChild( TreeNode node ); /** * Removes a node from the element. * * @param node * the node to remove */ void removeChild( TreeNode node ); /** * Appends all of the elements in the specified collection to the end of this list, in the order that they are returned by the specified collection's iterator (optional operation). The behavior of this operation is unspecified if the specified collection is modified while the operation is in progress. (Note that this will occur if the specified collection is this list, and it's nonempty.) * * @param c * the collection whose elements are to be added to this list. * @return * true if this list changed as a result of the call. * * @see java.util.List.addAll(Collection c) */ boolean addAllChildren( Collection<? extends TreeNode> c ); }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/wrappers/ProjectsViewRoot.java
plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/wrappers/ProjectsViewRoot.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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.apache.directory.studio.schemaeditor.view.wrappers; import org.apache.directory.studio.schemaeditor.Activator; import org.apache.directory.studio.schemaeditor.controller.ProjectsHandler; import org.apache.directory.studio.schemaeditor.controller.ProjectsHandlerListener; import org.apache.directory.studio.schemaeditor.model.Project; import org.eclipse.jface.viewers.TableViewer; import org.eclipse.swt.widgets.Display; /** * This wrapper is used as root in the ProjectsView. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class ProjectsViewRoot extends AbstractTreeNode { /** The TableViewer */ private TableViewer viewer; /** The ProjectsHandler */ private ProjectsHandler projectsHandler; /** * Creates a new instance of ProjectsViewRoot. * * @param tableViewer * the associated TableViewer */ public ProjectsViewRoot( TableViewer tableViewer ) { super( null ); this.viewer = tableViewer; projectsHandler = Activator.getDefault().getProjectsHandler(); projectsHandler.addListener( new ProjectsHandlerListener() { public void projectAdded( Project project ) { addProjectWrapper( project ); refreshProjectsViewer(); } public void projectRemoved( Project project ) { deleteProjectWrapper( project ); refreshProjectsViewer(); } public void openProjectChanged( Project oldProject, Project newProject ) { refreshProjectsViewer(); } } ); } /** * Add a ProjectWrapper for the given project. * * @param project * the project */ private void addProjectWrapper( Project project ) { addChild( new ProjectWrapper( project, viewer ) ); } /** * Deletes the ProjectWrapper associated with the given project. * * @param project * the project */ private void deleteProjectWrapper( Project project ) { for ( TreeNode node : getChildren() ) { ProjectWrapper pw = ( ProjectWrapper ) node; if ( project == pw.getProject() ) { removeChild( node ); return; } } } /** * Refreshes the Projects Viewer */ public void refreshProjectsViewer() { Display.getDefault().asyncExec( new Runnable() { public void run() { viewer.refresh(); } } ); } /** * {@inheritDoc} */ public boolean equals( Object obj ) { if ( obj instanceof ProjectsViewRoot ) { return this == obj; } return false; } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/wrappers/AttributeTypeWrapper.java
plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/wrappers/AttributeTypeWrapper.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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.apache.directory.studio.schemaeditor.view.wrappers; import org.apache.directory.api.ldap.model.schema.AttributeType; import org.eclipse.osgi.util.NLS; /** * This class is used to wrap an AttributeType in a TreeViewer. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class AttributeTypeWrapper extends AbstractTreeNode { /** The wrapped AttributeType */ private AttributeType attributeType; /** * Creates a new instance of AttributeTypeWrapper. * * @param at * the wrapped AttributeType */ public AttributeTypeWrapper( AttributeType at ) { super( null ); attributeType = at; } /** * Creates a new instance of AttributeTypeWrapper. * * @param at * the wrapped AttributeType * @param parent * the parent TreeNode */ public AttributeTypeWrapper( AttributeType at, TreeNode parent ) { super( parent ); attributeType = at; } /** * Gets the wrapped AttributeType. * * @return * the wrapped AttributeType */ public AttributeType getAttributeType() { return attributeType; } /** * {@inheritDoc} */ public boolean equals( Object obj ) { if ( obj instanceof AttributeTypeWrapper ) { if ( super.equals( obj ) ) { AttributeTypeWrapper atw = ( AttributeTypeWrapper ) obj; if ( ( attributeType != null ) && ( !attributeType.equals( atw.getAttributeType() ) ) ) { return false; } return true; } } // Default return false; } /** * {@inheritDoc} */ public int hashCode() { int result = super.hashCode(); if ( attributeType != null ) { result = 37 * result + attributeType.hashCode(); } return result; } /** * {@inheritDoc} */ public String toString() { return NLS.bind( Messages.getString( "AttributeTypeWrapper.AttributeTypeWrapper" ), new Object[] { attributeType, fParent } ); //$NON-NLS-1$ } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/wrappers/OidSorter.java
plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/wrappers/OidSorter.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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.apache.directory.studio.schemaeditor.view.wrappers; import java.util.Comparator; import org.apache.directory.api.ldap.model.schema.AttributeType; import org.apache.directory.api.ldap.model.schema.ObjectClass; /** * This class is used to compare and sort ascending two DisplayableTreeElement */ public class OidSorter implements Comparator<TreeNode> { /** * {@inheritDoc} */ public int compare( TreeNode o1, TreeNode o2 ) { if ( ( o1 instanceof AttributeTypeWrapper ) && ( o2 instanceof AttributeTypeWrapper ) ) { AttributeType at1 = ( ( AttributeTypeWrapper ) o1 ).getAttributeType(); AttributeType at2 = ( ( AttributeTypeWrapper ) o2 ).getAttributeType(); return at1.getOid().compareToIgnoreCase( at2.getOid() ); } else if ( ( o1 instanceof ObjectClassWrapper ) && ( o2 instanceof ObjectClassWrapper ) ) { ObjectClass oc1 = ( ( ObjectClassWrapper ) o1 ).getObjectClass(); ObjectClass oc2 = ( ( ObjectClassWrapper ) o2 ).getObjectClass(); return oc1.getOid().compareToIgnoreCase( oc2.getOid() ); } else if ( ( o1 instanceof AttributeTypeWrapper ) && ( o2 instanceof ObjectClassWrapper ) ) { AttributeType at = ( ( AttributeTypeWrapper ) o1 ).getAttributeType(); ObjectClass oc = ( ( ObjectClassWrapper ) o2 ).getObjectClass(); return at.getOid().compareToIgnoreCase( oc.getOid() ); } else if ( ( o1 instanceof ObjectClassWrapper ) && ( o2 instanceof AttributeTypeWrapper ) ) { ObjectClass oc = ( ( ObjectClassWrapper ) o1 ).getObjectClass(); AttributeType at = ( ( AttributeTypeWrapper ) o2 ).getAttributeType(); return oc.getOid().compareToIgnoreCase( at.getOid() ); } // Default return o1.toString().compareToIgnoreCase( o2.toString() ); } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/wrappers/AbstractTreeNode.java
plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/wrappers/AbstractTreeNode.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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.apache.directory.studio.schemaeditor.view.wrappers; import java.util.ArrayList; import java.util.Collection; import java.util.List; /** * This abstract class implements the TreeNode Interface. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public abstract class AbstractTreeNode implements TreeNode { /** The children */ protected List<TreeNode> fChildren; /** The parent */ protected TreeNode fParent; /** * Creates a new instance of AbstractTreeNode. * * @param parent * the parent element */ public AbstractTreeNode( TreeNode parent ) { fParent = parent; } /** * {@inheritDoc} */ public boolean hasChildren() { if ( fChildren == null ) { return false; } return !fChildren.isEmpty(); } /** * {@inheritDoc} */ public TreeNode getParent() { return fParent; } /** * {@inheritDoc} */ public void setParent( TreeNode parent ) { fParent = parent; } /** * {@inheritDoc} */ public List<TreeNode> getChildren() { if ( fChildren == null ) { fChildren = new ArrayList<TreeNode>(); } return fChildren; } /** * {@inheritDoc} */ public void addChild( TreeNode node ) { if ( fChildren == null ) { fChildren = new ArrayList<TreeNode>(); } if ( !fChildren.contains( node ) ) { fChildren.add( node ); } } /** * {@inheritDoc} */ public void removeChild( TreeNode node ) { if ( fChildren != null ) { fChildren.remove( node ); } } /** * {@inheritDoc} */ public boolean addAllChildren( Collection<? extends TreeNode> c ) { if ( fChildren == null ) { fChildren = new ArrayList<TreeNode>(); } return fChildren.addAll( c ); } /** * {@inheritDoc} */ public boolean equals( Object obj ) { if ( obj instanceof AbstractTreeNode ) { AbstractTreeNode atn = ( AbstractTreeNode ) obj; if ( ( fParent != null ) && ( !fParent.equals( atn.getParent() ) ) ) { return false; } return true; } // Default return false; } /** * {@inheritDoc} */ public int hashCode() { int result = 17; if ( fParent != null ) { result = 37 * result + fParent.hashCode(); } return result; } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/wrappers/SchemaWrapper.java
plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/wrappers/SchemaWrapper.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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.apache.directory.studio.schemaeditor.view.wrappers; import org.apache.directory.studio.schemaeditor.model.Schema; import org.eclipse.osgi.util.NLS; /** * This class is used to wrap an Schema in a TreeViewer. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class SchemaWrapper extends AbstractTreeNode { /** The wrapped Schema */ private Schema schema; /** * Creates a new instance of SchemaWrapper. * * @param schema * the wrapped Schema */ public SchemaWrapper( Schema schema ) { super( null ); this.schema = schema; } /** * Creates a new instance of SchemaWrapper. * * @param at * the wrapped Schema * @param parent * the parent TreeNode */ public SchemaWrapper( Schema schema, TreeNode parent ) { super( parent ); this.schema = schema; } /** * Gets the wrapped Schema. * * @return * the wrapped Schema */ public Schema getSchema() { return schema; } /** * {@inheritDoc} */ public boolean equals( Object obj ) { if ( obj instanceof SchemaWrapper ) { if ( super.equals( obj ) ) { SchemaWrapper sw = ( SchemaWrapper ) obj; if ( ( schema != null ) && ( !schema.equals( sw.getSchema() ) ) ) { return false; } return true; } } // Default return false; } /** * {@inheritDoc} */ public int hashCode() { int result = super.hashCode(); if ( schema != null ) { result = 37 * result + schema.hashCode(); } return result; } /** * {@inheritDoc} */ public String toString() { return NLS.bind( Messages.getString( "SchemaWrapper.SchemaWrapper" ), new Object[] { schema, fParent } ); //$NON-NLS-1$ } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/wrappers/SchemaWarningWrapper.java
plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/wrappers/SchemaWarningWrapper.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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.apache.directory.studio.schemaeditor.view.wrappers; import org.apache.directory.studio.schemaeditor.model.schemachecker.SchemaWarning; /** * This class is used to wrap a SchemaWarning in a TreeViewer. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class SchemaWarningWrapper extends AbstractTreeNode { /** The wrapped SchemaWarning */ private SchemaWarning schemaWarning; /** * Creates a new instance of SchemaWarningWrapper. * * @param warning * the wrapped SchemaWarning */ public SchemaWarningWrapper( SchemaWarning warning ) { super( null ); schemaWarning = warning; } /** * Creates a new instance of SchemaErrorWrapper. * * @param error * the wrapped SchemaError * @param parent * the parent TreeNode */ public SchemaWarningWrapper( SchemaWarning warning, TreeNode parent ) { super( parent ); schemaWarning = warning; } /** * Gets the wrapped SchemaWarning. * * @return * the wrapped SchemaWarning */ public SchemaWarning getSchemaWarning() { return schemaWarning; } /** * {@inheritDoc} */ public boolean hasChildren() { return false; } /** * {@inheritDoc} */ public boolean equals( Object obj ) { if ( obj instanceof SchemaWarningWrapper ) { if ( super.equals( obj ) ) { SchemaWarningWrapper sww = ( SchemaWarningWrapper ) obj; if ( ( schemaWarning != null ) && ( !schemaWarning.equals( sww.getSchemaWarning() ) ) ) { return false; } return true; } } // Default return false; } /** * {@inheritDoc} */ public int hashCode() { int result = super.hashCode(); if ( schemaWarning != null ) { result = 37 * result + schemaWarning.hashCode(); } return result; } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/wrappers/SchemaErrorWrapper.java
plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/wrappers/SchemaErrorWrapper.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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.apache.directory.studio.schemaeditor.view.wrappers; import org.apache.directory.api.ldap.model.exception.LdapSchemaException; /** * This class is used to wrap a SchemaError in a TreeViewer. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class SchemaErrorWrapper extends AbstractTreeNode { /** The wrapper {@link LdapSchemaException} */ private LdapSchemaException ldapSchemaException; /** * Creates a new instance of SchemaErrorWrapper. * * @param error * the wrapped SchemaError */ public SchemaErrorWrapper( LdapSchemaException ldapSchemaException ) { super( null ); this.ldapSchemaException = ldapSchemaException; } /** * Creates a new instance of SchemaErrorWrapper. * * @param error * the wrapped SchemaError * @param parent * the parent TreeNode */ public SchemaErrorWrapper( LdapSchemaException ldapSchemaException, TreeNode parent ) { super( parent ); this.ldapSchemaException = ldapSchemaException; } /** * Gets the wrapped {@link LdapSchemaException}. * * @return * the wrapped SchemaError */ public LdapSchemaException getLdapSchemaException() { return ldapSchemaException; } /** * {@inheritDoc} */ public boolean hasChildren() { return false; } /** * {@inheritDoc} */ public boolean equals( Object obj ) { if ( obj instanceof SchemaErrorWrapper ) { if ( super.equals( obj ) ) { SchemaErrorWrapper sww = ( SchemaErrorWrapper ) obj; if ( ( ldapSchemaException != null ) && ( !ldapSchemaException.equals( sww.getLdapSchemaException() ) ) ) { return false; } return true; } } // Default return false; } /** * {@inheritDoc} */ public int hashCode() { int result = super.hashCode(); if ( ldapSchemaException != null ) { result = 37 * result + ldapSchemaException.hashCode(); } return result; } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/wrappers/Folder.java
plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/wrappers/Folder.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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.apache.directory.studio.schemaeditor.view.wrappers; import org.eclipse.osgi.util.NLS; /** * This used to represent a folder in a TreeViewer. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class Folder extends AbstractTreeNode { /** * This enum represents the different types of folders. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public enum FolderType { NONE, ATTRIBUTE_TYPE, OBJECT_CLASS, ERROR, WARNING } /** The type of the Folder */ private FolderType type = FolderType.NONE; /** The name of the Folder */ private String name = ""; //$NON-NLS-1$ /** * Creates a new instance of Folder. * * @param type * the type of the Folder * @param parent * the parent TreeNode */ public Folder( FolderType type, TreeNode parent ) { super( parent ); this.type = type; switch ( type ) { case ATTRIBUTE_TYPE: name = Messages.getString( "Folder.AttributeTypes" ); //$NON-NLS-1$ break; case OBJECT_CLASS: name = Messages.getString( "Folder.ObjectClasses" ); //$NON-NLS-1$ break; case ERROR: name = Messages.getString( "Folder.Errors" ); //$NON-NLS-1$ break; case WARNING: name = Messages.getString( "Folder.Warnings" ); //$NON-NLS-1$ break; default: break; } } /** * Creates a new instance of Folder. * * @param type * the type of the Folder * @param name * the name of the Folder * @param parent * the parent TreeNode */ public Folder( FolderType type, String name, TreeNode parent ) { super( parent ); this.type = type; this.name = name; } /** * Get the type of the Folder. * * @return * the type of the Folder */ public FolderType getType() { return type; } /** * Gets the name of the Folder. * * @return * the name of the Folder */ public String getName() { return name; } /** * {@inheritDoc} */ public boolean equals( Object obj ) { if ( obj instanceof Folder ) { Folder folder = ( Folder ) obj; if ( ( getParent() != null ) && ( !getParent().equals( folder.getParent() ) ) ) { return false; } if ( !getType().equals( folder.getType() ) ) { return false; } if ( ( getName() != null ) && ( !getName().equals( folder.getName() ) ) ) { return false; } return true; } return false; } /** * {@inheritDoc} */ public int hashCode() { int result = super.hashCode(); if ( name != null ) { result = 37 * result + name.hashCode(); } if ( type != null ) { result = 37 * result + type.hashCode(); } return result; } /** * {@inheritDoc} */ public String toString() { return NLS.bind( Messages.getString( "Folder.Folder" ), new Object[] { type, fParent } ); //$NON-NLS-1$ } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/wrappers/difference/ObjectClassDifferenceWrapper.java
plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/wrappers/difference/ObjectClassDifferenceWrapper.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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.apache.directory.studio.schemaeditor.view.wrappers.difference; import org.apache.directory.studio.schemaeditor.view.wrappers.TreeNode; /** * This class represent the wrapper for an object class. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class ObjectClassDifferenceWrapper extends AbstractDifferenceWrapper { /** * Creates a new instance of ObjectClassDifferenceWrapper. * * @param originalObject * the original object class * @param modifiedObject * the modified object class * @param parent * the parent TreeNode */ public ObjectClassDifferenceWrapper( Object originalObject, Object modifiedObject, TreeNode parent ) { super( originalObject, modifiedObject, parent ); } /** * Creates a new instance of ObjectClassDifferenceWrapper. * * @param originalObject * the original object class * @param modifiedObject * the modified object class * @param state * the state of the wrapper * @param parent * the parent TreeNode */ public ObjectClassDifferenceWrapper( Object originalObject, Object modifiedObject, WrapperState state, TreeNode parent ) { super( originalObject, modifiedObject, state, parent ); } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/wrappers/difference/AttributeTypeDifferenceWrapper.java
plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/wrappers/difference/AttributeTypeDifferenceWrapper.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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.apache.directory.studio.schemaeditor.view.wrappers.difference; import org.apache.directory.studio.schemaeditor.view.wrappers.TreeNode; /** * This class represent the wrapper for an attribute type. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class AttributeTypeDifferenceWrapper extends AbstractDifferenceWrapper { /** * Creates a new instance of AttributeTypeDifferenceWrapper. * * @param originalObject * the original attribute type * @param modifiedObject * the modified attribute type * @param parent * the parent TreeNode */ public AttributeTypeDifferenceWrapper( Object originalObject, Object modifiedObject, TreeNode parent ) { super( originalObject, modifiedObject, parent ); } /** * Creates a new instance of AttributeTypeDifferenceWrapper. * * @param originalObject * the original attribute type * @param modifiedObject * the modified attribute type * @param state * the state of the wrapper * @param parent * the parent TreeNode */ public AttributeTypeDifferenceWrapper( Object originalObject, Object modifiedObject, WrapperState state, TreeNode parent ) { super( originalObject, modifiedObject, state, parent ); } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/wrappers/difference/AbstractDifferenceWrapper.java
plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/wrappers/difference/AbstractDifferenceWrapper.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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.apache.directory.studio.schemaeditor.view.wrappers.difference; import org.apache.directory.studio.schemaeditor.view.wrappers.AbstractTreeNode; import org.apache.directory.studio.schemaeditor.view.wrappers.TreeNode; /** * This class represents an abstract difference wrapper. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public abstract class AbstractDifferenceWrapper extends AbstractTreeNode { /** The original object */ private Object originalObject; /** The modified object */ private Object modifiedObject; /** The state */ private WrapperState state; /** * Creates a new instance of AbstractDifferenceWrapper. * * @param originalObject * the original object * @param modifiedObject * the modified object * @param parent * the parent TreeNode */ public AbstractDifferenceWrapper( Object originalObject, Object modifiedObject, TreeNode parent ) { super( parent ); this.originalObject = originalObject; this.modifiedObject = modifiedObject; } /** * Creates a new instance of AbstractDifferenceWrapper. * * @param originalObject * the original object * @param modifiedObject * the modified object * @param state * the state of the wrapper * @param parent * the parent TreeNode */ public AbstractDifferenceWrapper( Object originalObject, Object modifiedObject, WrapperState state, TreeNode parent ) { super( parent ); this.originalObject = originalObject; this.modifiedObject = modifiedObject; this.state = state; } /** * Gets the original object. * * @return * the original object */ public Object getOriginalObject() { return originalObject; } /** * Sets the original object. * * @param originalObject * the original object */ public void setOriginalObject( Object originalObject ) { this.originalObject = originalObject; } /** * Gets the modified object. * * @return * the modified object */ public Object getModifiedObject() { return modifiedObject; } /** * Sets the modified object * * @param modifiedObject * the modified object */ public void setModifiedObject( Object modifiedObject ) { this.modifiedObject = modifiedObject; } /** * Gets the state. * * @return * the state */ public WrapperState getState() { return state; } /** * Sets the state. * * @param state * the state */ public void setState( WrapperState state ) { this.state = state; } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/wrappers/difference/SchemaDifferenceWrapper.java
plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/wrappers/difference/SchemaDifferenceWrapper.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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.apache.directory.studio.schemaeditor.view.wrappers.difference; import org.apache.directory.studio.schemaeditor.view.wrappers.TreeNode; /** * This class represent the wrapper for a schema. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class SchemaDifferenceWrapper extends AbstractDifferenceWrapper { /** * Creates a new instance of SchemaDifferenceWrapper. * * @param originalObject * the original schema * @param modifiedObject * the modified schema * @param parent * the parent TreeNode */ public SchemaDifferenceWrapper( Object originalObject, Object modifiedObject, TreeNode parent ) { super( originalObject, modifiedObject, parent ); } /** * Creates a new instance of SchemaDifferenceWrapper. * * @param originalObject * the original schema * @param modifiedObject * the modified schema * @param state * the state of the wrapper * @param parent * the parent TreeNode */ public SchemaDifferenceWrapper( Object originalObject, Object modifiedObject, WrapperState state, TreeNode parent ) { super( originalObject, modifiedObject, state, parent ); } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/wrappers/difference/WrapperState.java
plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/wrappers/difference/WrapperState.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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.apache.directory.studio.schemaeditor.view.wrappers.difference; public enum WrapperState { IDENTICAL, ADDED, MODFIED, REMOVED }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/editors/NonExistingMatchingRule.java
plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/editors/NonExistingMatchingRule.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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.apache.directory.studio.schemaeditor.view.editors; /** * This class implements the Non Existing Matching Rule. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class NonExistingMatchingRule { /** The None matching rule name */ public static final String NONE = "(None)"; /** The name */ private String name; /** * Creates a new instance of NonExistingMatchingRule. * * @param name * the name the NonExistingMatchingRule */ public NonExistingMatchingRule( String name ) { this.name = name; } /** * Gets the name of the NonExistingMatchingRule. * * @return * the name of the NonExistingMatchingRule */ public String getName() { return name; } /** * Gets the displayable name of the NonExistingMatchingRule. * * @return * the displayable name of the NonExistingMatchingRule */ public String getDisplayName() { if ( name.equals( NONE ) ) { return NONE; } else { return name + " " + "(This matching rule doesnt exist)"; } } /** * {@inheritDoc} */ public boolean equals( Object obj ) { if ( obj instanceof NonExistingMatchingRule ) { return name.equalsIgnoreCase( ( ( NonExistingMatchingRule ) obj ).getName() ); } return false; } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/editors/NonExistingAttributeType.java
plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/editors/NonExistingAttributeType.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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.apache.directory.studio.schemaeditor.view.editors; /** * This class implements the Non Existing Attribute Type. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class NonExistingAttributeType { public static final String NONE = "(None)"; //$NON-NLS-1$ /** The name */ private String name; /** * Creates a new instance of NonExistingAttributeType. * * @param name * the name the NonExistingAttributeType */ public NonExistingAttributeType( String name ) { this.name = name; } /** * Gets the name of the NonExistingAttributeType. * * @return * the name of the NonExistingAttributeType */ public String getName() { return name; } /** * Gets the displayable name of the NonExistingAttributeType. * * @return * the displayable name of the NonExistingAttributeType */ public String getDisplayName() { if ( name.equals( NONE ) ) { return NONE; } else { return name + " " + "(This attribute type doesnt exist)"; } } /** * {@inheritDoc} */ public boolean equals( Object obj ) { if ( obj instanceof NonExistingAttributeType ) { return name.equalsIgnoreCase( ( ( NonExistingAttributeType ) obj ).getName() ); } return false; } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/editors/AbstractSchemaObjectEditorPage.java
plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/editors/AbstractSchemaObjectEditorPage.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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.apache.directory.studio.schemaeditor.view.editors; import org.eclipse.jface.viewers.ISelectionChangedListener; import org.eclipse.jface.viewers.Viewer; import org.eclipse.swt.custom.StyledText; import org.eclipse.swt.events.ModifyListener; import org.eclipse.swt.events.MouseListener; import org.eclipse.swt.events.SelectionListener; import org.eclipse.swt.events.VerifyListener; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Combo; import org.eclipse.swt.widgets.Table; import org.eclipse.swt.widgets.Text; import org.eclipse.ui.forms.IManagedForm; import org.eclipse.ui.forms.editor.FormEditor; import org.eclipse.ui.forms.editor.FormPage; import org.eclipse.ui.forms.events.IHyperlinkListener; import org.eclipse.ui.forms.widgets.Hyperlink; /** * This abstract class defines a schema object editor page. */ public abstract class AbstractSchemaObjectEditorPage<E extends FormEditor> extends FormPage { /** The flag to indicate if the page has been initialized */ protected boolean initialized = false; /** * Default constructor * * @param editor the parent editor * @param id the unique identifier * @param title the page title */ public AbstractSchemaObjectEditorPage( E editor, String id, String title ) { super( editor, id, title ); } /** * {@inheritDoc} */ @SuppressWarnings("unchecked") public E getEditor() { return ( E ) super.getEditor(); } /** * {@inheritDoc} */ protected void createFormContent( IManagedForm managedForm ) { initialized = true; } /** * Adds listeners to UI fields */ protected void addListeners() { } /** * Removes listeners from UI fields */ protected void removeListeners() { } /** * Initializes the UI fields from the input. */ protected void fillInUiFields() { } /** * {@inheritDoc} */ public void dispose() { removeListeners(); super.dispose(); } /** * Refreshes the UI. */ public void refreshUI() { if ( initialized ) { removeListeners(); fillInUiFields(); addListeners(); } } /** * Adds a modify listener to the given Text. * * @param text the Text control * @param listener the listener */ protected void addModifyListener( Text text, ModifyListener listener ) { if ( ( text != null ) && ( !text.isDisposed() ) && ( listener != null ) ) { text.addModifyListener( listener ); } } /** * Adds a modify listener to the given Text. * * @param text the StyledText control * @param listener the listener */ protected void addModifyListener( StyledText text, ModifyListener listener ) { if ( ( text != null ) && ( !text.isDisposed() ) && ( listener != null ) ) { text.addModifyListener( listener ); } } /** * Adds a modify listener to the given Text. * * @param combo the Combo control * @param listener the listener */ protected void addModifyListener( Combo combo, ModifyListener listener ) { if ( ( combo != null ) && ( !combo.isDisposed() ) && ( listener != null ) ) { combo.addModifyListener( listener ); } } /** * Adds a verify listener to the given Text. * * @param text the Text control * @param listener the listener */ protected void addVerifyListener( Text text, VerifyListener listener ) { if ( ( text != null ) && ( !text.isDisposed() ) && ( listener != null ) ) { text.addVerifyListener( listener ); } } /** * Adds a selection changed listener to the given Viewer. * * @param viewer the viewer control * @param listener the listener */ protected void addSelectionChangedListener( Viewer viewer, ISelectionChangedListener listener ) { if ( ( viewer != null ) && ( viewer.getControl() != null ) && ( !viewer.getControl().isDisposed() ) && ( listener != null ) ) { viewer.addSelectionChangedListener( listener ); } } /** * Adds an hyperlink listener to the given HyperLink. * * @param hyperLink the HyperLink * @param listener the listener */ protected void addHyperlinkListener( Hyperlink hyperLink, IHyperlinkListener listener ) { if ( ( hyperLink != null ) && ( !hyperLink.isDisposed() ) && ( listener != null ) ) { hyperLink.addHyperlinkListener( listener ); } } /** * Adds a selection listener to the given Button. * * @param button the Button control * @param listener the listener */ protected void addSelectionListener( Button button, SelectionListener listener ) { if ( ( button != null ) && ( !button.isDisposed() ) && ( listener != null ) ) { button.addSelectionListener( listener ); } } /** * Adds a mouse listener to the given Table. * * @param table the Table control * @param listener the listener */ protected void addMouseListener( Table table, MouseListener listener ) { if ( ( table != null ) && ( !table.isDisposed() ) && ( listener != null ) ) { table.addMouseListener( listener ); } } /** * Removes a modify listener from the given Text. * * @param text the Text control * @param listener the listener */ protected void removeModifyListener( Text text, ModifyListener listener ) { if ( ( text != null ) && ( !text.isDisposed() ) && ( listener != null ) ) { text.removeModifyListener( listener ); } } /** * Removes a modify listener from the given Text. * * @param text the StyledText control * @param listener the listener */ protected void removeModifyListener( StyledText text, ModifyListener listener ) { if ( ( text != null ) && ( !text.isDisposed() ) && ( listener != null ) ) { text.removeModifyListener( listener ); } } /** * Removes a modify listener from the given Text. * * @param combo the Combo control * @param listener the listener */ protected void removeModifyListener( Combo combo, ModifyListener listener ) { if ( ( combo != null ) && ( !combo.isDisposed() ) && ( listener != null ) ) { combo.removeModifyListener( listener ); } } /** * Removes a verify listener from the given Text. * * @param text the Text control * @param listener the listener */ protected void removeVerifyListener( Text text, VerifyListener listener ) { if ( ( text != null ) && ( !text.isDisposed() ) && ( listener != null ) ) { text.removeVerifyListener( listener ); } } /** * Removes a selection changed listener from the given Viewer. * * @param viewer * the viewer control * @param listener * the listener */ protected void removeSelectionChangedListener( Viewer viewer, ISelectionChangedListener listener ) { if ( ( viewer != null ) && ( viewer.getControl() != null ) && ( !viewer.getControl().isDisposed() ) && ( listener != null ) ) { viewer.removeSelectionChangedListener( listener ); } } /** * Removes an hyperlink listener from the given HyperLink. * * @param hyperLink the HyperLink * @param listener the listener */ protected void removeHyperlinkListener( Hyperlink hyperLink, IHyperlinkListener listener ) { if ( ( hyperLink != null ) && ( !hyperLink.isDisposed() ) && ( listener != null ) ) { hyperLink.removeHyperlinkListener( listener ); } } /** * Removes a selection listener from the given Button. * * @param button * the Button control * @param listener * the listener */ protected void removeSelectionListener( Button button, SelectionListener listener ) { if ( ( button != null ) && ( !button.isDisposed() ) && ( listener != null ) ) { button.removeSelectionListener( listener ); } } /** * Removes a mouse listener from the given Table. * * @param table the Table control * @param listener the listener */ protected void removeMouseListener( Table table, MouseListener listener ) { if ( ( table != null ) && ( !table.isDisposed() ) && ( listener != null ) ) { table.removeMouseListener( listener ); } } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/editors/NonExistingSyntax.java
plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/editors/NonExistingSyntax.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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.apache.directory.studio.schemaeditor.view.editors; /** * This class implements the Non Existing Syntax. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class NonExistingSyntax { /** The None syntax description */ public static final String NONE = "(None)"; //$NON-NLS-1$ /** The description */ private String description; /** * Creates a new instance of NonExistingSyntax. * * @param description * the description the NonExistingSyntax */ public NonExistingSyntax( String description ) { this.description = description; } /** * Gets the description of the NonExistingSyntax. * * @return * the description of the NonExistingSyntax */ public String getDescription() { return description; } /** * Gets the displayable name of the NonExistingSyntax. * * @return * the displayable name of the NonExistingSyntax */ public String getDisplayName() { if ( description.equals( NONE ) ) { return NONE; } else { return description + " " + "(This syntax doesnt exist)"; } } /** * {@inheritDoc} */ public boolean equals( Object obj ) { if ( obj instanceof NonExistingSyntax ) { return description.equalsIgnoreCase( ( ( NonExistingSyntax ) obj ).getDescription() ); } return false; } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/editors/EditorsUtils.java
plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/editors/EditorsUtils.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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.apache.directory.studio.schemaeditor.view.editors; import java.util.ArrayList; import java.util.List; import org.eclipse.jface.dialogs.Dialog; import org.eclipse.jface.viewers.ArrayContentProvider; import org.eclipse.jface.viewers.LabelProvider; import org.eclipse.swt.graphics.Image; import org.eclipse.ui.IEditorInput; import org.eclipse.ui.IEditorPart; import org.eclipse.ui.IWorkbench; import org.eclipse.ui.IWorkbenchPage; import org.eclipse.ui.IWorkbenchWindow; import org.eclipse.ui.PlatformUI; import org.eclipse.ui.dialogs.ListDialog; /** * This class implements a utility class for the editors. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class EditorsUtils { /** * Saves all the dirty editors (asking the user if they need to be saved or not). * * @return <code>true</code> if all the dirty editors were saved successfully, * <code>false</code> if not (if the user decided to not save them, or * if an error occurred when saving). */ public static boolean saveAllDirtyEditors() { IWorkbench workbench = PlatformUI.getWorkbench(); IWorkbenchWindow workbenchWindow = workbench.getActiveWorkbenchWindow(); List<IEditorPart> dirtyEditorsList = getDirtyEditorsList( workbench ); if ( dirtyEditorsList.size() > 0 ) { // Creating the dialog to ask the user if the dirty editors must be saved ListDialog dialog = new ListDialog( workbenchWindow.getShell() ); dialog.setTitle( Messages.getString( "EditorsUtils.SaveDialogTitle" ) ); //$NON-NLS-1$ dialog.setMessage( Messages.getString( "EditorsUtils.SaveDialogMessage" ) ); //$NON-NLS-1$ dialog.setLabelProvider( new LabelProvider() { public Image getImage( Object element ) { return ( ( IEditorPart ) element ).getTitleImage(); } public String getText( Object element ) { IEditorPart editorPart = ( IEditorPart ) element; StringBuilder sb = new StringBuilder(); sb.append( editorPart.getTitle() ); String tooltip = editorPart.getTitleToolTip(); if ( ( tooltip != null ) && ( !"".equals( tooltip ) ) ) //$NON-NLS-1$ { sb.append( " [" ); //$NON-NLS-1$ sb.append( tooltip ); sb.append( "]" ); //$NON-NLS-1$ } return sb.toString(); } } ); dialog.setContentProvider( new ArrayContentProvider() ); dialog.setHelpAvailable( false ); dialog.setAddCancelButton( true ); dialog.setInput( dirtyEditorsList ); // Opening the dialog if ( dialog.open() != Dialog.OK ) { // Cancel return false; } // Forcing the save of all dirty editors return workbenchWindow.getWorkbench().saveAllEditors( false ); } return true; } /** * Returns a list of all editors having unsaved content. * * @return a list of all dirty editors. */ public static List<IEditorPart> getDirtyEditorsList( IWorkbench workbench ) { List<IEditorPart> dirtyEditorsList = new ArrayList<IEditorPart>(); if ( workbench != null ) { List<IEditorInput> processedInputs = new ArrayList<IEditorInput>(); for ( IWorkbenchWindow workbenchWindow : workbench.getWorkbenchWindows() ) { for ( IWorkbenchPage workbenchPage : workbenchWindow.getPages() ) { for ( IEditorPart editor : workbenchPage.getDirtyEditors() ) { IEditorInput input = editor.getEditorInput(); if ( !processedInputs.contains( input ) ) { processedInputs.add( input ); dirtyEditorsList.add( editor ); } } } } } return dirtyEditorsList; } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/editors/Messages.java
plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/editors/Messages.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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.apache.directory.studio.schemaeditor.view.editors; import java.util.MissingResourceException; import java.util.ResourceBundle; /** * This class get messages from the resources file. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class Messages { /** The resource name */ private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle.getBundle( Messages.class.getPackage().getName() + ".messages" ); /** * Get back a message from the resource file given a key * * @param key The key associated with the message * @return The found message */ public static String getString( String key ) { try { return RESOURCE_BUNDLE.getString( key ); } catch ( MissingResourceException e ) { return '!' + key + '!'; } } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/editors/NonExistingObjectClass.java
plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/editors/NonExistingObjectClass.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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.apache.directory.studio.schemaeditor.view.editors; /** * This class implements the Non Existing Object Class. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class NonExistingObjectClass { public static final String NONE = "(None)"; //$NON-NLS-1$ /** The name */ private String name; /** * Creates a new instance of NonExistingObjectClass. * * @param name * the name the NonExistingObjectClass */ public NonExistingObjectClass( String name ) { this.name = name; } /** * Gets the name of the NonExistingObjectClass. * * @return * the name of the NonExistingObjectClass */ public String getName() { return name; } /** * Gets the displayable name of the NonExistingObjectClass. * * @return * the displayable name of the NonExistingObjectClass */ public String getDisplayName() { if ( name.equals( NONE ) ) { return NONE; } else { return name + " " + "(This object class doesnt exist)"; } } /** * {@inheritDoc} */ public boolean equals( Object obj ) { if ( obj instanceof NonExistingObjectClass ) { return name.equalsIgnoreCase( ( ( NonExistingObjectClass ) obj ).getName() ); } return false; } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/editors/objectclass/ObjectClassEditor.java
plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/editors/objectclass/ObjectClassEditor.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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.apache.directory.studio.schemaeditor.view.editors.objectclass; import org.apache.directory.api.ldap.model.schema.ObjectClass; import org.apache.directory.studio.schemaeditor.Activator; import org.apache.directory.studio.schemaeditor.PluginConstants; import org.apache.directory.studio.schemaeditor.PluginUtils; import org.apache.directory.studio.schemaeditor.controller.SchemaHandler; import org.apache.directory.studio.schemaeditor.controller.SchemaHandlerAdapter; import org.apache.directory.studio.schemaeditor.controller.SchemaHandlerListener; import org.apache.directory.studio.schemaeditor.model.Schema; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.jface.dialogs.IPageChangedListener; import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.jface.dialogs.PageChangedEvent; import org.eclipse.ui.IEditorInput; import org.eclipse.ui.IEditorSite; import org.eclipse.ui.PartInitException; import org.eclipse.ui.PlatformUI; import org.eclipse.ui.forms.editor.FormEditor; /** * This class is the ObjectClass Editor main class */ public class ObjectClassEditor extends FormEditor { /** The ID of the Editor */ public static final String ID = PluginConstants.EDITOR_OBJECT_CLASS_ID; /** The editor */ private ObjectClassEditor instance; // The pages private ObjectClassEditorOverviewPage overviewPage; private ObjectClassEditorSourceCodePage sourceCodePage; /** The dirty state flag */ private boolean dirty = false; /** The original object class */ private ObjectClass originalObjectClass; /** The object class used to save modifications */ private ObjectClass modifiedObjectClass; /** The originalSchema */ private Schema originalSchema; /** The listener for page changed */ private IPageChangedListener pageChangedListener = new IPageChangedListener() { public void pageChanged( PageChangedEvent event ) { Object selectedPage = event.getSelectedPage(); if ( selectedPage instanceof ObjectClassEditorOverviewPage ) { if ( !sourceCodePage.canLeaveThePage() ) { notifyError( Messages.getString( "ObjectClassEditor.CodeError" ) ); //$NON-NLS-1$ return; } overviewPage.refreshUI(); } else if ( selectedPage instanceof ObjectClassEditorSourceCodePage ) { if ( sourceCodePage.canLeaveThePage() ) { sourceCodePage.refreshUI(); } } } }; /** The SchemaHandler listener */ private SchemaHandlerListener schemaHandlerListener = new SchemaHandlerAdapter() { public void objectClassModified( ObjectClass oc ) { if ( oc.equals( originalObjectClass ) ) { // Updating the modified object class modifiedObjectClass = PluginUtils.getClone( originalObjectClass ); // Refreshing the editor pages overviewPage.refreshUI(); sourceCodePage.refreshUI(); // Refreshing the part name (in case of a change in the name) setPartName( getEditorInput().getName() ); } } public void objectClassRemoved( ObjectClass oc ) { if ( oc.equals( originalObjectClass ) ) { getEditorSite().getPage().closeEditor( instance, false ); } } public void schemaRemoved( Schema schema ) { if ( schema.equals( originalSchema ) ) { getEditorSite().getPage().closeEditor( instance, false ); } } public void schemaRenamed( Schema schema ) { if ( schema.equals( originalSchema ) ) { // Updating the modified object class modifiedObjectClass = PluginUtils.getClone( originalObjectClass ); // Refreshing the editor pages overviewPage.refreshUI(); sourceCodePage.refreshUI(); } } }; /** * {@inheritDoc} */ public void init( IEditorSite site, IEditorInput input ) throws PartInitException { super.init( site, input ); instance = this; setSite( site ); setInput( input ); setPartName( input.getName() ); originalObjectClass = ( ObjectClass ) ( ( ObjectClassEditorInput ) getEditorInput() ).getObjectClass(); modifiedObjectClass = PluginUtils.getClone( originalObjectClass ); SchemaHandler schemaHandler = Activator.getDefault().getSchemaHandler(); originalSchema = schemaHandler.getSchema( originalObjectClass.getSchemaName() ); schemaHandler.addListener( schemaHandlerListener ); addPageChangedListener( pageChangedListener ); } /** * {@inheritDoc} */ public void dispose() { SchemaHandler schemaHandler = Activator.getDefault().getSchemaHandler(); schemaHandler.removeListener( schemaHandlerListener ); super.dispose(); } /** * {@inheritDoc} */ protected void addPages() { try { overviewPage = new ObjectClassEditorOverviewPage( this ); addPage( overviewPage ); sourceCodePage = new ObjectClassEditorSourceCodePage( this ); addPage( sourceCodePage ); } catch ( PartInitException e ) { PluginUtils.logError( "error when adding pages", e ); //$NON-NLS-1$ } } /** * {@inheritDoc} */ public void doSave( IProgressMonitor monitor ) { // Verifying if there is an error on the source code page if ( !sourceCodePage.canLeaveThePage() ) { notifyError( Messages.getString( "ObjectClassEditor.CodeErrorObject" ) ); //$NON-NLS-1$ monitor.setCanceled( true ); return; } Activator.getDefault().getSchemaHandler().modifyObjectClass( originalObjectClass, modifiedObjectClass ); setPartName( getEditorInput().getName() ); if ( !monitor.isCanceled() ) { setDirty( false ); } } /** * {@inheritDoc} */ public void doSaveAs() { } /** * {@inheritDoc} */ public boolean isSaveAsAllowed() { return false; } /** * {@inheritDoc} */ public boolean isDirty() { return dirty; } /** * Sets the dirty state of the editor * * @param dirty * the dirty state */ public void setDirty( boolean dirty ) { this.dirty = dirty; editorDirtyStateChanged(); } /** * Gets the original object class. * * @return * the original object class */ public ObjectClass getOriginalObjectClass() { return originalObjectClass; } /** * Gets the modified object class. * * @return * the modified object class */ public ObjectClass getModifiedObjectClass() { return modifiedObjectClass; } /** * Sets the modified object class. * * @param modifiedObjectClass * the modified object class to set. */ public void setModifiedObjectClass( ObjectClass modifiedObjectClass ) { this.modifiedObjectClass = modifiedObjectClass; } /** * Opens an error dialog displaying the given message. * * @param message * the message to display */ private void notifyError( String message ) { MessageDialog.openError( PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), Messages.getString( "ObjectClassEditor.Error" ), message ); //$NON-NLS-1$ } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/editors/objectclass/ObjectClassEditorAttributesTableContentProvider.java
plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/editors/objectclass/ObjectClassEditorAttributesTableContentProvider.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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.apache.directory.studio.schemaeditor.view.editors.objectclass; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.List; import org.apache.directory.api.ldap.model.schema.AttributeType; import org.apache.directory.studio.schemaeditor.Activator; import org.apache.directory.studio.schemaeditor.controller.SchemaHandler; import org.apache.directory.studio.schemaeditor.view.editors.NonExistingAttributeType; import org.eclipse.jface.viewers.IStructuredContentProvider; import org.eclipse.jface.viewers.Viewer; /** * This class is the Content Provider for the Attributes Table of the Object Class Editor. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class ObjectClassEditorAttributesTableContentProvider implements IStructuredContentProvider { /** The Schema Pool */ private SchemaHandler schemaHandler; /** * Creates a new instance of ObjectClassEditorAttributesTableContentProvider. */ public ObjectClassEditorAttributesTableContentProvider() { schemaHandler = Activator.getDefault().getSchemaHandler(); } /** * {@inheritDoc} */ @SuppressWarnings("unchecked") public Object[] getElements( Object inputElement ) { if ( inputElement instanceof List<?> ) { List<Object> results = new ArrayList<Object>(); List<String> attributes = ( List<String> ) inputElement; for ( String attribute : attributes ) { AttributeType at = schemaHandler.getAttributeType( attribute ); if ( at != null ) { results.add( at ); } else { results.add( new NonExistingAttributeType( attribute ) ); } } // Sorting Elements Collections.sort( results, new Comparator<Object>() { public int compare( Object o1, Object o2 ) { if ( o1 instanceof AttributeType && o2 instanceof AttributeType ) { List<String> at1Names = ( ( AttributeType ) o1 ).getNames(); List<String> at2Names = ( ( AttributeType ) o2 ).getNames(); if ( ( at1Names != null ) && ( at2Names != null ) && ( at1Names.size() > 0 ) && ( at2Names.size() > 0 ) ) { return at1Names.get( 0 ).compareToIgnoreCase( at2Names.get( 0 ) ); } } else if ( o1 instanceof AttributeType && o2 instanceof NonExistingAttributeType ) { List<String> at1Names = ( ( AttributeType ) o1 ).getNames(); String at2Name = ( ( NonExistingAttributeType ) o2 ).getName(); if ( ( at1Names != null ) && ( at2Name != null ) && ( at1Names.size() > 0 ) ) { return at1Names.get( 0 ).compareToIgnoreCase( at2Name ); } } else if ( o1 instanceof NonExistingAttributeType && o2 instanceof AttributeType ) { String at1Name = ( ( NonExistingAttributeType ) o1 ).getName(); List<String> at2Names = ( ( AttributeType ) o2 ).getNames(); if ( ( at1Name != null ) && ( at2Names != null ) && ( at2Names.size() > 0 ) ) { return at1Name.compareToIgnoreCase( at2Names.get( 0 ) ); } } else if ( o1 instanceof NonExistingAttributeType && o2 instanceof NonExistingAttributeType ) { String at1Name = ( ( NonExistingAttributeType ) o1 ).getName(); String at2Name = ( ( NonExistingAttributeType ) o2 ).getName(); if ( ( at1Name != null ) && ( at2Name != null ) ) { return at1Name.compareToIgnoreCase( at2Name ); } } return 0; } } ); return results.toArray(); } // Default return null; } /** * {@inheritDoc} */ public void dispose() { } /** * {@inheritDoc} */ public void inputChanged( Viewer viewer, Object oldInput, Object newInput ) { } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/editors/objectclass/ObjectClassEditorSuperiorsTableContentProvider.java
plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/editors/objectclass/ObjectClassEditorSuperiorsTableContentProvider.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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.apache.directory.studio.schemaeditor.view.editors.objectclass; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.List; import org.apache.directory.api.ldap.model.schema.ObjectClass; import org.apache.directory.studio.schemaeditor.Activator; import org.apache.directory.studio.schemaeditor.controller.SchemaHandler; import org.apache.directory.studio.schemaeditor.view.editors.NonExistingObjectClass; import org.eclipse.jface.viewers.IStructuredContentProvider; import org.eclipse.jface.viewers.Viewer; /** * This class is the Content Provider for the Superiors Table of the Object * Class Editor. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class ObjectClassEditorSuperiorsTableContentProvider implements IStructuredContentProvider { /** The SchemaHandler */ private SchemaHandler schemaHandler; /** * Creates a new instance of * ObjectClassFormEditorSuperiorsTableContentProvider. */ public ObjectClassEditorSuperiorsTableContentProvider() { schemaHandler = Activator.getDefault().getSchemaHandler(); } /** * {@inheritDoc} */ @SuppressWarnings("unchecked") public Object[] getElements( Object inputElement ) { if ( inputElement instanceof List<?> ) { List<Object> results = new ArrayList<Object>(); List<String> superiors = ( List<String> ) inputElement; for ( String superior : superiors ) { ObjectClass oc = schemaHandler.getObjectClass( superior ); if ( oc != null ) { results.add( oc ); } else { results.add( new NonExistingObjectClass( superior ) ); } } // Sorting Elements Collections.sort( results, new Comparator<Object>() { public int compare( Object o1, Object o2 ) { if ( o1 instanceof ObjectClass && o2 instanceof ObjectClass ) { List<String> oc1Names = ( ( ObjectClass ) o1 ).getNames(); List<String> oc2Names = ( ( ObjectClass ) o2 ).getNames(); if ( ( oc1Names != null ) && ( oc2Names != null ) && ( oc1Names.size() > 0 ) && ( oc2Names.size() > 0 ) ) { return oc1Names.get( 0 ).compareToIgnoreCase( oc2Names.get( 0 ) ); } } else if ( o1 instanceof ObjectClass && o2 instanceof NonExistingObjectClass ) { List<String> oc1Names = ( ( ObjectClass ) o1 ).getNames(); String oc2Name = ( ( NonExistingObjectClass ) o2 ).getName(); if ( ( oc1Names != null ) && ( oc2Name != null ) && ( oc1Names.size() > 0 ) ) { return oc1Names.get( 0 ).compareToIgnoreCase( oc2Name ); } } else if ( o1 instanceof NonExistingObjectClass && o2 instanceof ObjectClass ) { String oc1Name = ( ( NonExistingObjectClass ) o1 ).getName(); List<String> oc2Names = ( ( ObjectClass ) o2 ).getNames(); if ( ( oc1Name != null ) && ( oc2Names != null ) && ( oc2Names.size() > 0 ) ) { return oc1Name.compareToIgnoreCase( oc2Names.get( 0 ) ); } } else if ( o1 instanceof NonExistingObjectClass && o2 instanceof NonExistingObjectClass ) { String oc1Name = ( ( NonExistingObjectClass ) o1 ).getName(); String oc2Name = ( ( NonExistingObjectClass ) o2 ).getName(); if ( ( oc1Name != null ) && ( oc2Name != null ) ) { return oc1Name.compareToIgnoreCase( oc2Name ); } } return 0; } } ); return results.toArray(); } // Default return null; } /** * {@inheritDoc} */ public void dispose() { } /** * {@inheritDoc} */ public void inputChanged( Viewer viewer, Object oldInput, Object newInput ) { } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/editors/objectclass/ObjectClassEditorOverviewPage.java
plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/editors/objectclass/ObjectClassEditorOverviewPage.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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.apache.directory.studio.schemaeditor.view.editors.objectclass; import java.util.ArrayList; import java.util.List; import org.apache.directory.api.asn1.util.Oid; import org.apache.directory.api.ldap.model.schema.AttributeType; import org.apache.directory.api.ldap.model.schema.LdapSyntax; import org.apache.directory.api.ldap.model.schema.MatchingRule; import org.apache.directory.api.ldap.model.schema.ObjectClass; import org.apache.directory.api.ldap.model.schema.ObjectClassTypeEnum; import org.apache.directory.studio.schemaeditor.Activator; import org.apache.directory.studio.schemaeditor.PluginConstants; import org.apache.directory.studio.schemaeditor.PluginUtils; import org.apache.directory.studio.schemaeditor.controller.SchemaHandler; import org.apache.directory.studio.schemaeditor.controller.SchemaHandlerListener; import org.apache.directory.studio.schemaeditor.model.Schema; import org.apache.directory.studio.schemaeditor.model.alias.Alias; import org.apache.directory.studio.schemaeditor.model.alias.AliasWithError; import org.apache.directory.studio.schemaeditor.model.alias.AliasesStringParser; import org.apache.directory.studio.schemaeditor.view.ViewUtils; import org.apache.directory.studio.schemaeditor.view.dialogs.AttributeTypeSelectionDialog; import org.apache.directory.studio.schemaeditor.view.dialogs.EditObjectClassAliasesDialog; import org.apache.directory.studio.schemaeditor.view.dialogs.ObjectClassSelectionDialog; import org.apache.directory.studio.schemaeditor.view.editors.NonExistingAttributeType; import org.apache.directory.studio.schemaeditor.view.editors.NonExistingObjectClass; import org.apache.directory.studio.schemaeditor.view.editors.attributetype.AttributeTypeEditor; import org.apache.directory.studio.schemaeditor.view.editors.attributetype.AttributeTypeEditorInput; import org.apache.directory.studio.schemaeditor.view.editors.schema.SchemaEditor; import org.apache.directory.studio.schemaeditor.view.editors.schema.SchemaEditorInput; import org.eclipse.jface.viewers.StructuredSelection; import org.eclipse.jface.viewers.TableViewer; import org.eclipse.swt.SWT; import org.eclipse.swt.events.ModifyEvent; import org.eclipse.swt.events.ModifyListener; import org.eclipse.swt.events.MouseAdapter; import org.eclipse.swt.events.MouseEvent; import org.eclipse.swt.events.MouseListener; import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.events.VerifyEvent; import org.eclipse.swt.events.VerifyListener; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Combo; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Event; import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Listener; import org.eclipse.swt.widgets.Table; import org.eclipse.swt.widgets.Text; import org.eclipse.ui.IWorkbenchPage; import org.eclipse.ui.PartInitException; import org.eclipse.ui.PlatformUI; import org.eclipse.ui.forms.IManagedForm; import org.eclipse.ui.forms.events.HyperlinkAdapter; import org.eclipse.ui.forms.events.HyperlinkEvent; import org.eclipse.ui.forms.widgets.FormToolkit; import org.eclipse.ui.forms.widgets.Hyperlink; import org.eclipse.ui.forms.widgets.ScrolledForm; import org.eclipse.ui.forms.widgets.Section; /** * This class is the Overview Page of the Object Class Editor */ public class ObjectClassEditorOverviewPage extends AbstractObjectClassEditorPage { /** The page ID */ public static final String ID = ObjectClassEditor.ID + "overviewPage"; //$NON-NLS-1$ /** The original schema */ private Schema originalSchema; /** The SchemaHandler */ private SchemaHandler schemaHandler; /** The SchemaHandler Listener */ private SchemaHandlerListener schemaHandlerListener = new SchemaHandlerListener() { public void attributeTypeAdded( AttributeType at ) { refreshUI(); } public void attributeTypeModified( AttributeType at ) { refreshUI(); } public void attributeTypeRemoved( AttributeType at ) { refreshUI(); } public void matchingRuleAdded( MatchingRule mr ) { refreshUI(); } public void matchingRuleModified( MatchingRule mr ) { refreshUI(); } public void matchingRuleRemoved( MatchingRule mr ) { refreshUI(); } public void objectClassAdded( ObjectClass oc ) { refreshUI(); } public void objectClassModified( ObjectClass oc ) { refreshUI(); } public void objectClassRemoved( ObjectClass oc ) { if ( !oc.equals( getOriginalObjectClass() ) ) { refreshUI(); } } public void schemaAdded( Schema schema ) { refreshUI(); } public void schemaRemoved( Schema schema ) { if ( !schema.equals( originalSchema ) ) { refreshUI(); } } public void schemaRenamed( Schema schema ) { refreshUI(); } public void syntaxAdded( LdapSyntax syntax ) { refreshUI(); } public void syntaxModified( LdapSyntax syntax ) { refreshUI(); } public void syntaxRemoved( LdapSyntax syntax ) { refreshUI(); } }; // UI fields private Text aliasesText; private Button aliasesButton; private Text oidText; private Hyperlink schemaLink; private Label schemaLabel; private Text descriptionText; private Table superiorsTable; private TableViewer superiorsTableViewer; private Button addButtonSuperiorsTable; private Button removeButtonSuperiorsTable; private Combo classTypeCombo; private Button obsoleteCheckbox; private Table mandatoryAttributesTable; private TableViewer mandatoryAttributesTableViewer; private Button addButtonMandatoryTable; private Button removeButtonMandatoryTable; private Table optionalAttributesTable; private TableViewer optionalAttributesTableViewer; private Button addButtonOptionalTable; private Button removeButtonOptionalTable; // Listeners /** The listener for the Aliases Text Widget */ private ModifyListener aliasesTextModifyListener = new ModifyListener() { public void modifyText( ModifyEvent e ) { ObjectClass modifiedObjectClass = getModifiedObjectClass(); AliasesStringParser parser = new AliasesStringParser(); parser.parse( aliasesText.getText() ); List<Alias> parsedAliases = parser.getAliases(); modifiedObjectClass.setNames( new String[0] ); List<String> aliasesList = new ArrayList<String>(); for ( Alias parsedAlias : parsedAliases ) { if ( !( parsedAlias instanceof AliasWithError ) ) { aliasesList.add( parsedAlias.getAlias() ); } } modifiedObjectClass.setNames( aliasesList.toArray( new String[0] ) ); setEditorDirty(); } }; /** The listener for Aliases Button Widget */ private SelectionAdapter aliasesButtonListener = new SelectionAdapter() { public void widgetSelected( SelectionEvent e ) { ObjectClass modifiedObjectClass = getModifiedObjectClass(); EditObjectClassAliasesDialog dialog = new EditObjectClassAliasesDialog( modifiedObjectClass.getNames() ); if ( dialog.open() == EditObjectClassAliasesDialog.OK ) { modifiedObjectClass.setNames( dialog.getAliases() ); if ( ( modifiedObjectClass.getNames() != null ) && ( modifiedObjectClass.getNames().size() != 0 ) ) { aliasesText.setText( ViewUtils.concateAliases( modifiedObjectClass.getNames() ) ); } else { aliasesText.setText( "" ); //$NON-NLS-1$ } setEditorDirty(); } } }; /** The Modify listener for the OID Text Widget */ private ModifyListener oidTextModifyListener = new ModifyListener() { public void modifyText( ModifyEvent e ) { oidText.setForeground( ViewUtils.COLOR_BLACK ); oidText.setToolTipText( "" ); //$NON-NLS-1$ ObjectClass modifiedObjectClass = getModifiedObjectClass(); String oid = oidText.getText(); if ( Oid.isOid( oid ) ) { if ( ( getOriginalObjectClass().getOid().equals( oid ) ) || !( schemaHandler.isOidAlreadyTaken( oid ) ) ) { modifiedObjectClass.setOid( oid ); setEditorDirty(); } else { oidText.setForeground( ViewUtils.COLOR_RED ); oidText.setToolTipText( Messages.getString( "ObjectClassEditorOverviewPage.ElementOIDExists" ) ); //$NON-NLS-1$ } } else { oidText.setForeground( ViewUtils.COLOR_RED ); oidText.setToolTipText( Messages.getString( "ObjectClassEditorOverviewPage.MalformedOID" ) ); //$NON-NLS-1$ } } }; /** The Verify listener for the OID Text Widget */ private VerifyListener oidTextVerifyListener = new VerifyListener() { public void verifyText( VerifyEvent e ) { if ( !e.text.matches( "([0-9]*\\.?)*" ) ) //$NON-NLS-1$ { e.doit = false; } } }; /** The listener for the Schema Hyperlink Widget*/ private HyperlinkAdapter schemaLinkListener = new HyperlinkAdapter() { public void linkActivated( HyperlinkEvent e ) { IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); SchemaEditorInput input = new SchemaEditorInput( schemaHandler.getSchema( getModifiedObjectClass() .getSchemaName() ) ); String editorId = SchemaEditor.ID; try { page.openEditor( input, editorId ); } catch ( PartInitException exception ) { PluginUtils.logError( "error when opening the editor", exception ); //$NON-NLS-1$ } } }; /** The listener for Description Text Widget */ private ModifyListener descriptionTextListener = new ModifyListener() { public void modifyText( ModifyEvent e ) { int caretPosition = descriptionText.getCaretPosition(); getModifiedObjectClass().setDescription( descriptionText.getText() ); descriptionText.setSelection( caretPosition ); setEditorDirty(); } }; /** The listener for Class Type Widget */ private ModifyListener classTypeListener = new ModifyListener() { public void modifyText( ModifyEvent e ) { ObjectClass modifiedObjectClass = getModifiedObjectClass(); if ( classTypeCombo.getSelectionIndex() == 0 ) { modifiedObjectClass.setType( ObjectClassTypeEnum.ABSTRACT ); } else if ( classTypeCombo.getSelectionIndex() == 1 ) { modifiedObjectClass.setType( ObjectClassTypeEnum.AUXILIARY ); } else if ( classTypeCombo.getSelectionIndex() == 2 ) { modifiedObjectClass.setType( ObjectClassTypeEnum.STRUCTURAL ); } setEditorDirty(); } }; /** The listener for Obsolete Widget */ private SelectionAdapter obsoleteListener = new SelectionAdapter() { public void widgetSelected( SelectionEvent e ) { getModifiedObjectClass().setObsolete( obsoleteCheckbox.getSelection() ); setEditorDirty(); } }; /** The listener for Mandatory Attributes Table Widget */ private MouseListener mandatoryAttributesTableListener = new MouseListener() { public void mouseDoubleClick( MouseEvent e ) { StructuredSelection selection = ( StructuredSelection ) mandatoryAttributesTableViewer.getSelection(); if ( selection.isEmpty() ) { return; } Object selectedElement = selection.getFirstElement(); if ( selectedElement != null ) { if ( selectedElement instanceof AttributeType ) { IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); try { page.openEditor( new AttributeTypeEditorInput( ( AttributeType ) selectedElement ), AttributeTypeEditor.ID ); } catch ( PartInitException exception ) { PluginUtils.logError( "error when opening the editor", exception ); //$NON-NLS-1$ } } } } public void mouseDown( MouseEvent e ) { } public void mouseUp( MouseEvent e ) { removeButtonMandatoryTable.setEnabled( mandatoryAttributesTable.getSelection().length != 0 ); } }; /** The listener for Add Button Widget of the Mandatory Attributes section */ private SelectionAdapter addButtonMandatoryTableListener = new SelectionAdapter() { public void widgetSelected( SelectionEvent e ) { ObjectClass modifiedObjectClass = getModifiedObjectClass(); AttributeTypeSelectionDialog dialog = new AttributeTypeSelectionDialog(); List<AttributeType> hiddenATs = new ArrayList<AttributeType>(); List<String> mustsHidden = modifiedObjectClass.getMustAttributeTypeOids(); if ( mustsHidden != null ) { for ( String must : mustsHidden ) { AttributeType at = schemaHandler.getAttributeType( must ); if ( at != null ) { hiddenATs.add( at ); } } } dialog.setHiddenAttributeTypes( hiddenATs.toArray( new AttributeType[0] ) ); if ( dialog.open() != AttributeTypeSelectionDialog.OK ) { return; } AttributeType at = dialog.getSelectedAttributeType(); if ( at == null ) { return; } List<String> newMusts = new ArrayList<String>(); List<String> musts = modifiedObjectClass.getMustAttributeTypeOids(); if ( musts != null ) { for ( String must : musts ) { newMusts.add( must ); } } List<String> names = at.getNames(); if ( ( names != null ) && ( names.size() > 0 ) ) { newMusts.add( names.get( 0 ) ); } else { newMusts.add( at.getOid() ); } modifiedObjectClass.setMustAttributeTypeOids( newMusts ); fillInMandatoryAttributesTable(); setEditorDirty(); } }; /** The listener for Remove Button Widget of the Mandatory Attributes section */ private SelectionAdapter removeButtonMandatoryTableListener = new SelectionAdapter() { public void widgetSelected( SelectionEvent e ) { StructuredSelection selection = ( StructuredSelection ) mandatoryAttributesTableViewer.getSelection(); if ( selection.isEmpty() ) { return; } ObjectClass modifiedObjectClass = getModifiedObjectClass(); Object selectedElement = selection.getFirstElement(); if ( selectedElement != null ) { List<String> newMusts = new ArrayList<String>(); List<String> musts = modifiedObjectClass.getMustAttributeTypeOids(); for ( String must : musts ) { newMusts.add( must ); } if ( selectedElement instanceof AttributeType ) { for ( String name : ( ( AttributeType ) selectedElement ).getNames() ) { newMusts.remove( name ); } } else if ( selectedElement instanceof NonExistingAttributeType ) { newMusts.remove( ( ( NonExistingAttributeType ) selectedElement ).getName() ); } modifiedObjectClass.setMustAttributeTypeOids( newMusts ); fillInMandatoryAttributesTable(); addButtonMandatoryTable.setFocus(); removeButtonMandatoryTable.setEnabled( mandatoryAttributesTable.getSelection().length != 0 ); setEditorDirty(); } } }; /** The listener for Optional Attributes Table Widget */ private MouseListener optionalAttributesTableListener = new MouseAdapter() { public void mouseDoubleClick( MouseEvent e ) { StructuredSelection selection = ( StructuredSelection ) optionalAttributesTableViewer.getSelection(); if ( selection.isEmpty() ) { return; } Object selectedElement = selection.getFirstElement(); if ( selectedElement != null ) { if ( selectedElement instanceof AttributeType ) { IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); try { page.openEditor( new AttributeTypeEditorInput( ( AttributeType ) selectedElement ), AttributeTypeEditor.ID ); } catch ( PartInitException exception ) { PluginUtils.logError( "error when opening the editor", exception ); //$NON-NLS-1$ } } } } public void mouseUp( MouseEvent e ) { removeButtonOptionalTable.setEnabled( optionalAttributesTable.getSelection().length != 0 ); } }; /** The listener for Add Button Widget of the Optional Attributes section */ private SelectionAdapter addButtonOptionalTableListener = new SelectionAdapter() { public void widgetSelected( SelectionEvent e ) { ObjectClass modifiedObjectClass = getModifiedObjectClass(); AttributeTypeSelectionDialog dialog = new AttributeTypeSelectionDialog(); List<AttributeType> hiddenATs = new ArrayList<AttributeType>(); List<String> maysHidden = modifiedObjectClass.getMayAttributeTypeOids(); if ( maysHidden != null ) { for ( String may : maysHidden ) { AttributeType at = schemaHandler.getAttributeType( may ); if ( at != null ) { hiddenATs.add( at ); } } } dialog.setHiddenAttributeTypes( hiddenATs.toArray( new AttributeType[0] ) ); if ( dialog.open() != AttributeTypeSelectionDialog.OK ) { return; } AttributeType at = dialog.getSelectedAttributeType(); if ( at == null ) { return; } List<String> newMays = new ArrayList<String>(); List<String> mays = modifiedObjectClass.getMayAttributeTypeOids(); if ( mays != null ) { for ( String may : mays ) { newMays.add( may ); } } List<String> names = at.getNames(); if ( ( names != null ) && ( names.size() > 0 ) ) { newMays.add( names.get( 0 ) ); } else { newMays.add( at.getOid() ); } modifiedObjectClass.setMayAttributeTypeOids( newMays ); fillInOptionalAttributesTable(); setEditorDirty(); } }; /** The listener for Remove Button Widget of the Optional Attributes section */ private SelectionAdapter removeButtonOptionalTableListener = new SelectionAdapter() { public void widgetSelected( SelectionEvent e ) { StructuredSelection selection = ( StructuredSelection ) optionalAttributesTableViewer.getSelection(); if ( selection.isEmpty() ) { return; } ObjectClass modifiedObjectClass = getModifiedObjectClass(); Object selectedElement = selection.getFirstElement(); if ( selectedElement != null ) { List<String> newMays = new ArrayList<String>(); List<String> mays = modifiedObjectClass.getMayAttributeTypeOids(); for ( String may : mays ) { newMays.add( may ); } if ( selectedElement instanceof AttributeType ) { for ( String name : ( ( AttributeType ) selectedElement ).getNames() ) { newMays.remove( name ); } } else if ( selectedElement instanceof NonExistingAttributeType ) { newMays.remove( ( ( NonExistingAttributeType ) selectedElement ).getName() ); } modifiedObjectClass.setMayAttributeTypeOids( newMays ); fillInOptionalAttributesTable(); addButtonOptionalTable.setFocus(); removeButtonOptionalTable.setEnabled( optionalAttributesTable.getSelection().length != 0 ); setEditorDirty(); } } }; /** The listener for Superiors Table Widget */ private MouseListener superiorsTableListener = new MouseAdapter() { public void mouseDoubleClick( MouseEvent e ) { StructuredSelection selection = ( StructuredSelection ) superiorsTableViewer.getSelection(); if ( selection.isEmpty() ) { return; } Object selectedElement = selection.getFirstElement(); if ( selectedElement != null ) { if ( selectedElement instanceof ObjectClass ) { IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); try { page.openEditor( new ObjectClassEditorInput( ( ObjectClass ) selectedElement ), ObjectClassEditor.ID ); } catch ( PartInitException exception ) { PluginUtils.logError( "error when opening the editor", exception ); //$NON-NLS-1$ } } } } public void mouseUp( MouseEvent e ) { removeButtonSuperiorsTable.setEnabled( superiorsTable.getSelection().length != 0 ); } }; /** The listener for Add Button Widget of the Superiors Table */ private SelectionAdapter addButtonSuperiorsTableListener = new SelectionAdapter() { public void widgetSelected( SelectionEvent e ) { ObjectClass modifiedObjectClass = getModifiedObjectClass(); ObjectClassSelectionDialog dialog = new ObjectClassSelectionDialog(); List<ObjectClass> hiddenOCs = new ArrayList<ObjectClass>(); for ( String sup : modifiedObjectClass.getSuperiorOids() ) { ObjectClass oc = schemaHandler.getObjectClass( sup ); if ( oc != null ) { hiddenOCs.add( oc ); } } hiddenOCs.add( getOriginalObjectClass() ); dialog.setHiddenObjectClasses( hiddenOCs.toArray( new ObjectClass[0] ) ); if ( dialog.open() != ObjectClassSelectionDialog.OK ) { return; } ObjectClass oc = dialog.getSelectedObjectClass(); if ( oc == null ) { return; } List<String> superiors = new ArrayList<String>(); List<String> sups = modifiedObjectClass.getSuperiorOids(); for ( String sup : sups ) { superiors.add( sup ); } List<String> names = oc.getNames(); if ( ( names != null ) && ( names.size() > 0 ) ) { superiors.add( names.get( 0 ) ); } else { superiors.add( oc.getOid() ); } modifiedObjectClass.setSuperiorOids( superiors ); fillInSuperiorsTable(); setEditorDirty(); } }; /** The listener for Remove Button Widget of the Superiors Table */ private SelectionAdapter removeButtonSuperiorsTableListener = new SelectionAdapter() { public void widgetSelected( SelectionEvent e ) { StructuredSelection selection = ( StructuredSelection ) superiorsTableViewer.getSelection(); if ( selection.isEmpty() ) { return; } ObjectClass modifiedObjectClass = getModifiedObjectClass(); Object selectedElement = selection.getFirstElement(); if ( selectedElement != null ) { List<String> superiors = new ArrayList<String>(); List<String> sups = modifiedObjectClass.getSuperiorOids(); for ( String sup : sups ) { superiors.add( sup ); } if ( selectedElement instanceof ObjectClass ) { for ( String name : ( ( ObjectClass ) selectedElement ).getNames() ) { superiors.remove( name ); } } else if ( selectedElement instanceof NonExistingObjectClass ) { superiors.remove( ( ( NonExistingObjectClass ) selectedElement ).getName() ); } modifiedObjectClass.setSuperiorOids( superiors ); fillInSuperiorsTable(); addButtonSuperiorsTable.setFocus(); removeButtonSuperiorsTable.setEnabled( superiorsTable.getSelection().length != 0 ); setEditorDirty(); } } }; /** The filter listener for Mouse Wheel events */ private Listener mouseWheelFilter = new Listener() { public void handleEvent( Event event ) { // Hiding Mouse Wheel events for Combo widgets if ( event.widget instanceof Combo ) { event.doit = false; } } }; /** * Default constructor. * * @param editor the associated editor */ public ObjectClassEditorOverviewPage( ObjectClassEditor editor ) { super( editor, ID, Messages.getString( "ObjectClassEditorOverviewPage.Overview" ) ); //$NON-NLS-1$ schemaHandler = Activator.getDefault().getSchemaHandler(); schemaHandler.addListener( schemaHandlerListener ); } /** * {@inheritDoc} */ protected void createFormContent( IManagedForm managedForm ) { super.createFormContent( managedForm ); // Creating the base UI ScrolledForm form = managedForm.getForm(); FormToolkit toolkit = managedForm.getToolkit(); form.getBody().setLayout( new GridLayout() ); // General Information Section createGeneralInformationSection( form.getBody(), toolkit ); Composite bottomComposite = toolkit.createComposite( form.getBody() ); bottomComposite.setLayout( new GridLayout( 2, true ) ); bottomComposite.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) ); // Mandatory Attributes Section createMandatoryAttributesSection( bottomComposite, toolkit ); // Optionnal Attributes Section createOptionalAttributesSection( bottomComposite, toolkit ); // Filling the UI with values from the object class fillInUiFields(); // Listeners initialization addListeners(); // Help Context for Dynamic Help PlatformUI.getWorkbench().getHelpSystem().setHelp( form, PluginConstants.PLUGIN_ID + "." + "object_class_editor" ); //$NON-NLS-1$ //$NON-NLS-2$ } /** * Creates the General Information Section. * * @param parent * the parent composite * @param toolkit * the FormToolKit to use */ private void createGeneralInformationSection( Composite parent, FormToolkit toolkit ) { // General Information Section Section section_general_information = toolkit.createSection( parent, Section.DESCRIPTION | Section.EXPANDED | Section.TITLE_BAR ); section_general_information.setDescription( Messages .getString( "ObjectClassEditorOverviewPage.SpecifyGeneralInformation" ) ); //$NON-NLS-1$ section_general_information.setText( Messages.getString( "ObjectClassEditorOverviewPage.GeneralInformation" ) ); //$NON-NLS-1$ section_general_information.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) ); // Creating the layout of the section Composite client_general_information = toolkit.createComposite( section_general_information ); client_general_information.setLayout( new GridLayout( 2, false ) ); toolkit.paintBordersFor( client_general_information ); section_general_information.setClient( client_general_information ); section_general_information.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) ); // Adding elements to the section // ALIASES Button toolkit.createLabel( client_general_information, Messages.getString( "ObjectClassEditorOverviewPage.Aliases" ) ); //$NON-NLS-1$ Composite aliasComposite = toolkit.createComposite( client_general_information ); GridLayout aliasCompositeGridLayout = new GridLayout( 2, false ); toolkit.paintBordersFor( aliasComposite ); aliasCompositeGridLayout.marginHeight = 1; aliasCompositeGridLayout.marginWidth = 1; aliasComposite.setLayout( aliasCompositeGridLayout ); aliasComposite.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) ); aliasesText = toolkit.createText( aliasComposite, "" ); //$NON-NLS-1$ aliasesText.setLayoutData( new GridData( SWT.FILL, SWT.CENTER, true, false ) );
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
true
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/editors/objectclass/Messages.java
plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/editors/objectclass/Messages.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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.apache.directory.studio.schemaeditor.view.editors.objectclass; import java.util.MissingResourceException; import java.util.ResourceBundle; /** * This class get messages from the resources file. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class Messages { /** The resource name */ private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle.getBundle( Messages.class.getPackage().getName() + ".messages" ); /** * Get back a message from the resource file given a key * * @param key The key associated with the message * @return The found message */ public static String getString( String key ) { try { return RESOURCE_BUNDLE.getString( key ); } catch ( MissingResourceException e ) { return '!' + key + '!'; } } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/editors/objectclass/ObjectClassEditorSourceCodePage.java
plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/editors/objectclass/ObjectClassEditorSourceCodePage.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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.apache.directory.studio.schemaeditor.view.editors.objectclass; import java.text.ParseException; import java.util.List; import org.apache.directory.api.ldap.model.schema.ObjectClass; import org.apache.directory.api.ldap.model.schema.parsers.OpenLdapSchemaParser; import org.apache.directory.studio.schemaeditor.PluginConstants; import org.apache.directory.studio.schemaeditor.model.io.OpenLdapSchemaFileExporter; import org.apache.directory.studio.schemaeditor.view.widget.SchemaSourceViewer; import org.eclipse.jface.resource.JFaceResources; import org.eclipse.jface.text.Document; import org.eclipse.jface.text.IDocument; import org.eclipse.swt.SWT; import org.eclipse.swt.events.ModifyEvent; import org.eclipse.swt.events.ModifyListener; import org.eclipse.swt.graphics.Font; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.ui.PlatformUI; import org.eclipse.ui.forms.IManagedForm; import org.eclipse.ui.forms.widgets.FormToolkit; import org.eclipse.ui.forms.widgets.ScrolledForm; /** * This class is the Source Code Page of the Object Class Editor */ public class ObjectClassEditorSourceCodePage extends AbstractObjectClassEditorPage { /** The page ID */ public static final String ID = ObjectClassEditor.ID + "sourceCodePage"; //$NON-NLS-1$ /** The Schema Source Viewer */ private SchemaSourceViewer schemaSourceViewer; /** The flag to indicate if the user can leave the Source Code page */ private boolean canLeaveThePage = true; /** The listener of the Schema Source Viewer Widget */ private ModifyListener schemaSourceViewerListener = new ModifyListener() { public void modifyText( ModifyEvent e ) { canLeaveThePage = true; try { getEditor().setDirty( true ); OpenLdapSchemaParser parser = new OpenLdapSchemaParser(); parser.parse( schemaSourceViewer.getTextWidget().getText() ); List<?> objectclasses = parser.getObjectClasses(); if ( objectclasses.size() != 1 ) { // TODO Throw an exception and return } else { updateObjectClass( ( ObjectClass ) objectclasses.get( 0 ) ); } } catch ( ParseException exception ) { canLeaveThePage = false; } } }; /** * Default constructor. * * @param editor the associated editor */ public ObjectClassEditorSourceCodePage( ObjectClassEditor editor ) { super( editor, ID, Messages.getString( "ObjectClassEditorSourceCodePage.SourceCode" ) ); //$NON-NLS-1$ } /** * {@inheritDoc} */ protected void createFormContent( IManagedForm managedForm ) { super.createFormContent( managedForm ); ScrolledForm form = managedForm.getForm(); FormToolkit toolkit = managedForm.getToolkit(); GridLayout layout = new GridLayout(); layout.marginWidth = 0; layout.marginHeight = 0; form.getBody().setLayout( layout ); toolkit.paintBordersFor( form.getBody() ); // SOURCE CODE Field schemaSourceViewer = new SchemaSourceViewer( form.getBody(), null, null, false, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL ); GridData gd = new GridData( SWT.FILL, SWT.FILL, true, true ); gd.heightHint = 10; schemaSourceViewer.getTextWidget().setLayoutData( gd ); // set text font Font font = JFaceResources.getFont( JFaceResources.TEXT_FONT ); schemaSourceViewer.getTextWidget().setFont( font ); IDocument document = new Document(); schemaSourceViewer.setDocument( document ); // Initialization from the "input" object class fillInUiFields(); // Listeners initialization addListeners(); // Help Context for Dynamic Help PlatformUI.getWorkbench().getHelpSystem().setHelp( form, PluginConstants.PLUGIN_ID + "." + "object_class_editor" ); //$NON-NLS-1$ //$NON-NLS-2$ } /** * {@inheritDoc} */ protected void addListeners() { if ( schemaSourceViewer != null ) { schemaSourceViewer.getTextWidget().addModifyListener( schemaSourceViewerListener ); } } /** * {@inheritDoc} */ protected void removeListeners() { if ( schemaSourceViewer != null ) { schemaSourceViewer.getTextWidget().removeModifyListener( schemaSourceViewerListener ); } } /** * {@inheritDoc} */ protected void fillInUiFields() { schemaSourceViewer.getDocument().set( OpenLdapSchemaFileExporter.toSourceCode( getModifiedObjectClass() ) ); } /** * {@inheritDoc} */ public boolean canLeaveThePage() { return canLeaveThePage; } /** * Updates the Modified Object Class from the given Object Class Literal. * * @param ocl * the Object Class Literal */ private void updateObjectClass( ObjectClass ocl ) { ObjectClass modifiedObjectClass = getModifiedObjectClass(); modifiedObjectClass.setDescription( ocl.getDescription() ); modifiedObjectClass.setMayAttributeTypeOids( ocl.getMayAttributeTypeOids() ); modifiedObjectClass.setMustAttributeTypeOids( ocl.getMustAttributeTypeOids() ); modifiedObjectClass.setNames( ocl.getNames() ); modifiedObjectClass.setObsolete( ocl.isObsolete() ); modifiedObjectClass.setOid( ocl.getOid() ); modifiedObjectClass.setSuperiorOids( ocl.getSuperiorOids() ); modifiedObjectClass.setType( ocl.getType() ); } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/editors/objectclass/ObjectClassEditorInput.java
plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/editors/objectclass/ObjectClassEditorInput.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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.apache.directory.studio.schemaeditor.view.editors.objectclass; import java.util.List; import org.apache.directory.api.ldap.model.schema.ObjectClass; import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.osgi.util.NLS; import org.eclipse.ui.IEditorInput; import org.eclipse.ui.IPersistableElement; /** * This class is the Input class for the Object Class Editor */ public class ObjectClassEditorInput implements IEditorInput { /** The input object class */ private ObjectClass objectClass; /** * Default constructor. * * @param obj * the object class */ public ObjectClassEditorInput( ObjectClass obj ) { super(); objectClass = obj; } /** * {@inheritDoc} */ public boolean exists() { return ( objectClass == null ); } /** * {@inheritDoc} */ public ImageDescriptor getImageDescriptor() { return null; } /** * {@inheritDoc} */ public String getName() { List<String> names = objectClass.getNames(); if ( ( names != null ) && ( names.size() > 0 ) ) { return names.get( 0 ); } else { return objectClass.getOid(); } } /** * {@inheritDoc} */ public IPersistableElement getPersistable() { return null; } /** * {@inheritDoc} */ public String getToolTipText() { return NLS.bind( Messages.getString( "ObjectClassEditorInput.FromSchema" ), new String[] //$NON-NLS-1$ { getName(), objectClass.getSchemaName() } ); } /** * {@inheritDoc} */ @SuppressWarnings("rawtypes") public Object getAdapter( Class adapter ) { return null; } /** * {@inheritDoc} */ public boolean equals( Object obj ) { if ( this == obj ) return true; if ( !( obj instanceof ObjectClassEditorInput ) ) return false; ObjectClassEditorInput other = ( ObjectClassEditorInput ) obj; return other.getObjectClass().equals( this.objectClass ); } /** * Returns the input object class * * @return * the input object class */ public ObjectClass getObjectClass() { return this.objectClass; } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/editors/objectclass/ObjectClassEditorAttributesTableLabelProvider.java
plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/editors/objectclass/ObjectClassEditorAttributesTableLabelProvider.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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.apache.directory.studio.schemaeditor.view.editors.objectclass; import java.util.List; import org.apache.directory.api.ldap.model.schema.AttributeType; import org.apache.directory.studio.schemaeditor.Activator; import org.apache.directory.studio.schemaeditor.PluginConstants; import org.apache.directory.studio.schemaeditor.view.ViewUtils; import org.apache.directory.studio.schemaeditor.view.editors.NonExistingAttributeType; import org.eclipse.jface.viewers.ITableLabelProvider; import org.eclipse.jface.viewers.LabelProvider; import org.eclipse.osgi.util.NLS; import org.eclipse.swt.graphics.Image; /** * This class is the Label Provider for the Attributes Table of the Object Class Editor. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class ObjectClassEditorAttributesTableLabelProvider extends LabelProvider implements ITableLabelProvider { /** * {@inheritDoc} */ public Image getColumnImage( Object element, int columnIndex ) { if ( ( element instanceof AttributeType ) || ( element instanceof NonExistingAttributeType ) ) { return Activator.getDefault().getImage( PluginConstants.IMG_ATTRIBUTE_TYPE ); } // Default return null; } /** * {@inheritDoc} */ public String getColumnText( Object element, int columnIndex ) { if ( element instanceof AttributeType ) { AttributeType at = ( AttributeType ) element; List<String> names = at.getNames(); if ( ( names != null ) && ( names.size() > 0 ) ) { return ViewUtils.concateAliases( names ) + " - (" + at.getOid() + ")"; //$NON-NLS-1$ //$NON-NLS-2$ } else { return NLS .bind( Messages.getString( "ObjectClassEditorAttributesTableLabelProvider.none" ), new String[] { at.getOid() } ); //$NON-NLS-1$ } } else if ( element instanceof NonExistingAttributeType ) { return ( ( NonExistingAttributeType ) element ).getDisplayName(); } // Default return null; } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/editors/objectclass/ObjectClassEditorSuperiorsTableLabelProvider.java
plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/editors/objectclass/ObjectClassEditorSuperiorsTableLabelProvider.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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.apache.directory.studio.schemaeditor.view.editors.objectclass; import java.util.List; import org.apache.directory.api.ldap.model.schema.ObjectClass; import org.apache.directory.studio.schemaeditor.Activator; import org.apache.directory.studio.schemaeditor.PluginConstants; import org.apache.directory.studio.schemaeditor.view.ViewUtils; import org.apache.directory.studio.schemaeditor.view.editors.NonExistingObjectClass; import org.eclipse.jface.viewers.ITableLabelProvider; import org.eclipse.jface.viewers.LabelProvider; import org.eclipse.osgi.util.NLS; import org.eclipse.swt.graphics.Image; /** * This class is the Label Provider for the Superiors Table of the Object Class Editor. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class ObjectClassEditorSuperiorsTableLabelProvider extends LabelProvider implements ITableLabelProvider { /** * {@inheritDoc} */ public Image getColumnImage( Object element, int columnIndex ) { if ( ( element instanceof ObjectClass ) || ( element instanceof NonExistingObjectClass ) ) { return Activator.getDefault().getImage( PluginConstants.IMG_OBJECT_CLASS ); } // Default return null; } /** * {@inheritDoc} */ public String getColumnText( Object element, int columnIndex ) { if ( element instanceof ObjectClass ) { ObjectClass oc = ( ObjectClass ) element; List<String> names = oc.getNames(); if ( ( names != null ) && ( names.size() > 0 ) ) { return ViewUtils.concateAliases( names ) + " - (" + oc.getOid() + ")"; //$NON-NLS-1$ //$NON-NLS-2$ } else { return NLS .bind( Messages.getString( "ObjectClassEditorSuperiorsTableLabelProvider.None" ), new String[] { oc.getOid() } ); //$NON-NLS-1$ } } else if ( element instanceof NonExistingObjectClass ) { return ( ( NonExistingObjectClass ) element ).getDisplayName(); } // Default return null; } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/editors/objectclass/AbstractObjectClassEditorPage.java
plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/editors/objectclass/AbstractObjectClassEditorPage.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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.apache.directory.studio.schemaeditor.view.editors.objectclass; import org.apache.directory.api.ldap.model.schema.ObjectClass; import org.apache.directory.studio.schemaeditor.view.editors.AbstractSchemaObjectEditorPage; /** * This abstract class defines an object class editor page. */ public abstract class AbstractObjectClassEditorPage extends AbstractSchemaObjectEditorPage<ObjectClassEditor> { /** The flag to indicate if the page has been initialized */ protected boolean initialized = false; /** * Default constructor * * @param editor the parent editor * @param id the unique identifier * @param title the page title */ public AbstractObjectClassEditorPage( ObjectClassEditor editor, String id, String title ) { super( editor, id, title ); } /** * Gets the original object class. * * @return * the original object class */ public ObjectClass getOriginalObjectClass() { return getEditor().getOriginalObjectClass(); } /** * Gets the modified object class. * * @return * the modified object class */ public ObjectClass getModifiedObjectClass() { return getEditor().getModifiedObjectClass(); } /** * Sets the editor as dirty */ protected void setEditorDirty() { getEditor().setDirty( true ); } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/editors/attributetype/ATESyntaxComboInput.java
plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/editors/attributetype/ATESyntaxComboInput.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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.apache.directory.studio.schemaeditor.view.editors.attributetype; import java.util.ArrayList; import java.util.List; /** * This class implements the Input of the Syntax Combo of the Attribute Type Editor * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class ATESyntaxComboInput { /** The children */ private List<Object> children; /** * Adds a child. * * @param child * the child to add */ public void addChild( Object child ) { if ( children == null ) { children = new ArrayList<Object>(); } children.add( child ); } /** * Gets the children. * * @return * the children */ public List<Object> getChildren() { if ( children == null ) { children = new ArrayList<Object>(); } return children; } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/editors/attributetype/AttributeTypeEditorSourceCodePage.java
plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/editors/attributetype/AttributeTypeEditorSourceCodePage.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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.apache.directory.studio.schemaeditor.view.editors.attributetype; import java.text.ParseException; import java.util.List; import org.apache.directory.api.ldap.model.schema.AttributeType; import org.apache.directory.api.ldap.model.schema.parsers.OpenLdapSchemaParser; import org.apache.directory.studio.schemaeditor.PluginConstants; import org.apache.directory.studio.schemaeditor.model.io.OpenLdapSchemaFileExporter; import org.apache.directory.studio.schemaeditor.view.widget.SchemaSourceViewer; import org.eclipse.jface.resource.JFaceResources; import org.eclipse.jface.text.Document; import org.eclipse.jface.text.IDocument; import org.eclipse.swt.SWT; import org.eclipse.swt.events.ModifyEvent; import org.eclipse.swt.events.ModifyListener; import org.eclipse.swt.graphics.Font; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.ui.PlatformUI; import org.eclipse.ui.forms.IManagedForm; import org.eclipse.ui.forms.widgets.FormToolkit; import org.eclipse.ui.forms.widgets.ScrolledForm; /** * This class is the Source Code Page of the Attribute Type Editor */ public class AttributeTypeEditorSourceCodePage extends AbstractAttributeTypeEditorPage { /** The page ID */ public static final String ID = AttributeTypeEditor.ID + "sourceCodePage"; //$NON-NLS-1$ /** The Schema Source Viewer */ private SchemaSourceViewer schemaSourceViewer; /** The flag to indicate if the user can leave the Source Code page */ private boolean canLeaveThePage = true; /** The listener of the Schema Source Editor Widget */ private ModifyListener schemaSourceViewerListener = new ModifyListener() { public void modifyText( ModifyEvent e ) { canLeaveThePage = true; try { getEditor().setDirty( true ); OpenLdapSchemaParser parser = new OpenLdapSchemaParser(); parser.parse( schemaSourceViewer.getTextWidget().getText() ); List<?> attributeTypes = parser.getAttributeTypes(); if ( attributeTypes.size() != 1 ) { // Throw an exception and return } else { updateAttributeType( ( AttributeType ) attributeTypes.get( 0 ) ); } } catch ( ParseException e1 ) { canLeaveThePage = false; } } }; /** * Default constructor * * @param editor * the associated editor */ public AttributeTypeEditorSourceCodePage( AttributeTypeEditor editor ) { super( editor, ID, Messages.getString( "AttributeTypeEditorSourceCodePage.SourceCode" ) ); //$NON-NLS-1$ } /** * {@inheritDoc} */ protected void createFormContent( IManagedForm managedForm ) { super.createFormContent( managedForm ); ScrolledForm form = managedForm.getForm(); FormToolkit toolkit = managedForm.getToolkit(); GridLayout layout = new GridLayout(); layout.marginWidth = 0; layout.marginHeight = 0; form.getBody().setLayout( layout ); toolkit.paintBordersFor( form.getBody() ); // SOURCE CODE Field schemaSourceViewer = new SchemaSourceViewer( form.getBody(), null, null, false, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL ); GridData gd = new GridData( SWT.FILL, SWT.FILL, true, true ); gd.heightHint = 10; schemaSourceViewer.getTextWidget().setLayoutData( gd ); // set text font Font font = JFaceResources.getFont( JFaceResources.TEXT_FONT ); schemaSourceViewer.getTextWidget().setFont( font ); IDocument document = new Document(); schemaSourceViewer.setDocument( document ); // Initialization from the "input" attribute type fillInUiFields(); // Listeners initialization addListeners(); // Help Context for Dynamic Help PlatformUI.getWorkbench().getHelpSystem().setHelp( form, PluginConstants.PLUGIN_ID + "." + "attribute_type_editor" ); //$NON-NLS-1$ //$NON-NLS-2$ initialized = true; } /** * {@inheritDoc} */ protected void addListeners() { if ( schemaSourceViewer != null ) { addModifyListener( schemaSourceViewer.getTextWidget(), schemaSourceViewerListener ); } } /** * {@inheritDoc} */ protected void removeListeners() { if ( schemaSourceViewer != null ) { removeModifyListener( schemaSourceViewer.getTextWidget(), schemaSourceViewerListener ); } } /** * {@inheritDoc} */ protected void fillInUiFields() { schemaSourceViewer.getDocument().set( OpenLdapSchemaFileExporter.toSourceCode( getModifiedAttributeType() ) ); } /** * {@inheritDoc} */ public boolean canLeaveThePage() { return canLeaveThePage; } /** * Updates the Modified Attribute Type from the given Attribute Type * Literal. * * @param atl * the Attribute Type Literal */ private void updateAttributeType( AttributeType atl ) { AttributeType modifiedAttributeType = getModifiedAttributeType(); modifiedAttributeType.setCollective( atl.isCollective() ); modifiedAttributeType.setDescription( atl.getDescription() ); modifiedAttributeType.setEqualityOid( atl.getEqualityOid() ); modifiedAttributeType.setSyntaxLength( atl.getSyntaxLength() ); modifiedAttributeType.setNames( atl.getNames() ); modifiedAttributeType.setObsolete( atl.isObsolete() ); modifiedAttributeType.setOid( atl.getOid() ); modifiedAttributeType.setOrderingOid( atl.getOrderingOid() ); modifiedAttributeType.setSingleValued( atl.isSingleValued() ); modifiedAttributeType.setSubstringOid( atl.getSubstringOid() ); modifiedAttributeType.setSuperiorOid( atl.getSuperiorOid() ); modifiedAttributeType.setSyntaxOid( atl.getSyntaxOid() ); modifiedAttributeType.setUsage( atl.getUsage() ); modifiedAttributeType.setUserModifiable( atl.isUserModifiable() ); } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/editors/attributetype/ATESyntaxComboLabelProvider.java
plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/editors/attributetype/ATESyntaxComboLabelProvider.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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.apache.directory.studio.schemaeditor.view.editors.attributetype; import org.apache.directory.api.ldap.model.schema.LdapSyntax; import org.apache.directory.studio.schemaeditor.view.editors.NonExistingSyntax; import org.eclipse.jface.viewers.LabelProvider; import org.eclipse.osgi.util.NLS; /** * This class implements the Label Provider of the Syntax Combo of the Attribute Type Editor. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class ATESyntaxComboLabelProvider extends LabelProvider { /** * {@inheritDoc} */ public String getText( Object obj ) { if ( obj instanceof LdapSyntax ) { LdapSyntax syntax = ( LdapSyntax ) obj; // Getting description (and name for backward compatibility) String description = syntax.getDescription(); String name = syntax.getName(); if ( ( description != null ) || ( name != null ) ) { StringBuilder sb = new StringBuilder(); if ( description != null ) { // Using description sb.append( description ); } else { // Using name (for backward compatibility) sb.append( name ); } sb.append( " - (" ); //$NON-NLS-1$ sb.append( syntax.getOid() ); sb.append( ")" ); //$NON-NLS-1$ return sb.toString(); } else { return NLS.bind( Messages.getString( "ATESyntaxComboLabelProvider.None" ), new String[] { syntax.getOid() } ); //$NON-NLS-1$ } } else if ( obj instanceof NonExistingSyntax ) { return ( ( NonExistingSyntax ) obj ).getDisplayName(); } // Default return null; } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/editors/attributetype/ATESuperiorComboLabelProvider.java
plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/editors/attributetype/ATESuperiorComboLabelProvider.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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.apache.directory.studio.schemaeditor.view.editors.attributetype; import java.util.List; import org.apache.directory.api.ldap.model.schema.AttributeType; import org.apache.directory.studio.schemaeditor.view.ViewUtils; import org.apache.directory.studio.schemaeditor.view.editors.NonExistingAttributeType; import org.eclipse.jface.viewers.LabelProvider; import org.eclipse.osgi.util.NLS; /** * This class implements the Label Provider of the Superior Combo of the Attribute Type Editor. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class ATESuperiorComboLabelProvider extends LabelProvider { /** * {@inheritDoc} */ public String getText( Object obj ) { if ( obj instanceof AttributeType ) { AttributeType at = ( AttributeType ) obj; List<String> names = at.getNames(); if ( ( names != null ) && ( names.size() > 0 ) ) { return ViewUtils.concateAliases( names ) + " - (" + at.getOid() + ")"; //$NON-NLS-1$ //$NON-NLS-2$ } else { return NLS.bind( Messages.getString( "ATESuperiorComboLabelProvider.None" ), new String[] { at.getOid() } ); //$NON-NLS-1$ } } else if ( obj instanceof NonExistingAttributeType ) { return ( ( NonExistingAttributeType ) obj ).getDisplayName(); } // Default return null; } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/editors/attributetype/AttributeTypeEditorInput.java
plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/editors/attributetype/AttributeTypeEditorInput.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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.apache.directory.studio.schemaeditor.view.editors.attributetype; import java.util.List; import org.apache.directory.api.ldap.model.schema.AttributeType; import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.osgi.util.NLS; import org.eclipse.ui.IEditorInput; import org.eclipse.ui.IPersistableElement; /** * This class is the Input class for the Attribute Type Editor */ public class AttributeTypeEditorInput implements IEditorInput { /** The input attribute type */ private AttributeType attributeType; /** * Default constructor * * @param at * the input attribute type */ public AttributeTypeEditorInput( AttributeType at ) { attributeType = at; } /** * {@inheritDoc} */ public boolean exists() { return ( this.attributeType == null ); } /** * {@inheritDoc} */ public ImageDescriptor getImageDescriptor() { return null; } /** * {@inheritDoc} */ public String getName() { List<String> names = attributeType.getNames(); if ( ( names != null ) && ( names.size() > 0 ) ) { return names.get( 0 ); } else { return attributeType.getOid(); } } /** * {@inheritDoc} */ public IPersistableElement getPersistable() { return null; } /** * {@inheritDoc} */ public String getToolTipText() { return NLS.bind( Messages.getString( "AttributeTypeEditorInput.FromSchema" ), new String[] //$NON-NLS-1$ { getName(), attributeType.getSchemaName() } ); } /** * {@inheritDoc} */ @SuppressWarnings("rawtypes") public Object getAdapter( Class adapter ) { return null; } /** * {@inheritDoc} */ public boolean equals( Object obj ) { if ( this == obj ) { return true; } else if ( !( obj instanceof AttributeTypeEditorInput ) ) { return false; } AttributeTypeEditorInput other = ( AttributeTypeEditorInput ) obj; return other.getAttributeType().equals( this.attributeType ); } /** * Returns the input Attribute Type. * * @return * the input Attribute Type */ public AttributeType getAttributeType() { return this.attributeType; } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/editors/attributetype/AbstractAttributeTypeEditorPage.java
plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/editors/attributetype/AbstractAttributeTypeEditorPage.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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.apache.directory.studio.schemaeditor.view.editors.attributetype; import org.apache.directory.api.ldap.model.schema.AttributeType; import org.apache.directory.studio.schemaeditor.view.editors.AbstractSchemaObjectEditorPage; /** * This abstract class defines an attribute type editor page. */ public abstract class AbstractAttributeTypeEditorPage extends AbstractSchemaObjectEditorPage<AttributeTypeEditor> { /** The flag to indicate if the page has been initialized */ protected boolean initialized = false; /** * Default constructor * * @param editor the parent editor * @param id the unique identifier * @param title the page title */ public AbstractAttributeTypeEditorPage( AttributeTypeEditor editor, String id, String title ) { super( editor, id, title ); } /** * Gets the original attribute type. * * @return * the original attribute type */ public AttributeType getOriginalAttributeType() { return getEditor().getOriginalAttributeType(); } /** * Gets the modified attribute type. * * @return * the modified attribute type */ public AttributeType getModifiedAttributeType() { return getEditor().getModifiedAttributeType(); } /** * Sets the editor as dirty */ protected void setEditorDirty() { getEditor().setDirty( true ); } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/editors/attributetype/ATEUsedByMandatoryTableContentProvider.java
plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/editors/attributetype/ATEUsedByMandatoryTableContentProvider.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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.apache.directory.studio.schemaeditor.view.editors.attributetype; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.List; import org.apache.directory.api.ldap.model.schema.AttributeType; import org.apache.directory.api.ldap.model.schema.ObjectClass; import org.apache.directory.api.util.Strings; import org.apache.directory.studio.schemaeditor.Activator; import org.apache.directory.studio.schemaeditor.controller.SchemaHandler; import org.eclipse.jface.viewers.IStructuredContentProvider; import org.eclipse.jface.viewers.Viewer; /** * This class is the Content Provider for the Mandatory Table of the Attribute Type Editor (Used By Page). * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class ATEUsedByMandatoryTableContentProvider implements IStructuredContentProvider { /** * {@inheritDoc} */ public Object[] getElements( Object inputElement ) { if ( inputElement instanceof AttributeType ) { List<ObjectClass> results = new ArrayList<ObjectClass>(); AttributeType inputAT = ( AttributeType ) inputElement; SchemaHandler schemaHandler = Activator.getDefault().getSchemaHandler(); List<String> names = new ArrayList<String>(); List<String> atNames = inputAT.getNames(); if ( atNames != null ) { for ( String name : atNames ) { names.add( Strings.toLowerCase( name ) ); } } List<ObjectClass> objectClasses = schemaHandler.getObjectClasses(); for ( ObjectClass oc : objectClasses ) { List<String> musts = oc.getMustAttributeTypeOids(); if ( musts != null ) { for ( String must : musts ) { if ( names.contains( Strings.toLowerCase( must ) ) ) { results.add( oc ); } } } } // Sorting Results Collections.sort( results, new Comparator<ObjectClass>() { public int compare( ObjectClass oc1, ObjectClass oc2 ) { if ( oc1 instanceof ObjectClass && oc1 instanceof ObjectClass ) { List<String> oc1Names = ( ( ObjectClass ) oc1 ).getNames(); List<String> oc2Names = ( ( ObjectClass ) oc2 ).getNames(); if ( ( oc1Names != null ) && ( oc2Names != null ) && ( oc1Names.size() > 0 ) && ( oc2Names.size() > 0 ) ) { return oc1Names.get( 0 ).compareToIgnoreCase( oc2Names.get( 0 ) ); } } return 0; } } ); return results.toArray(); } // Default return null; } /** * {@inheritDoc} */ public void dispose() { } /** * {@inheritDoc} */ public void inputChanged( Viewer viewer, Object oldInput, Object newInput ) { } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/editors/attributetype/ATEMatchingRulesComboInput.java
plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/editors/attributetype/ATEMatchingRulesComboInput.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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.apache.directory.studio.schemaeditor.view.editors.attributetype; import java.util.ArrayList; import java.util.List; /** * This class implements the Input of the Matching Rules Combo of the Attribute Type Editor * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class ATEMatchingRulesComboInput { /** The children */ private List<Object> children; /** * Adds a child. * * @param child * the child to add */ public void addChild( Object child ) { if ( children == null ) { children = new ArrayList<Object>(); } children.add( child ); } /** * Gets the children. * * @return * the children */ public List<Object> getChildren() { if ( children == null ) { children = new ArrayList<Object>(); } return children; } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/editors/attributetype/ATESyntaxComboContentProvider.java
plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/editors/attributetype/ATESyntaxComboContentProvider.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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.apache.directory.studio.schemaeditor.view.editors.attributetype; import java.util.Collections; import java.util.List; import org.apache.directory.api.ldap.model.schema.LdapSyntax; import org.apache.directory.studio.schemaeditor.Activator; import org.apache.directory.studio.schemaeditor.view.editors.NonExistingSyntax; import org.eclipse.jface.viewers.IStructuredContentProvider; import org.eclipse.jface.viewers.Viewer; /** * This class implements the Content Provider for the Syntax Combo of the Attribute Type Editor. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class ATESyntaxComboContentProvider implements IStructuredContentProvider { /** * {@inheritDoc} */ public Object[] getElements( Object inputElement ) { if ( inputElement instanceof ATESyntaxComboInput ) { ATESyntaxComboInput input = ( ATESyntaxComboInput ) inputElement; if ( input.getChildren().isEmpty() ) { // Creating the '(None)' item input.addChild( new NonExistingSyntax( NonExistingSyntax.NONE ) ); // Creating Children List<LdapSyntax> syntaxes = Activator.getDefault().getSchemaHandler().getSyntaxes(); for ( LdapSyntax syntax : syntaxes ) { input.addChild( syntax ); } } // Getting Children List<Object> children = input.getChildren(); // Sorting Children Collections.sort( children, new ATESyntaxComboComparator() ); return children.toArray(); } // Default return new Object[0]; } /** * {@inheritDoc} */ public void dispose() { } /** * {@inheritDoc} */ public void inputChanged( Viewer viewer, Object oldInput, Object newInput ) { } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/editors/attributetype/Messages.java
plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/editors/attributetype/Messages.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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.apache.directory.studio.schemaeditor.view.editors.attributetype; import java.util.MissingResourceException; import java.util.ResourceBundle; /** * This class get messages from the resources file. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class Messages { /** The resource name */ private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle.getBundle( Messages.class.getPackage().getName() + ".messages" ); /** * Get back a message from the resource file given a key * * @param key The key associated with the message * @return The found message */ public static String getString( String key ) { try { return RESOURCE_BUNDLE.getString( key ); } catch ( MissingResourceException e ) { return '!' + key + '!'; } } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/editors/attributetype/ATESyntaxComboComparator.java
plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/editors/attributetype/ATESyntaxComboComparator.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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.apache.directory.studio.schemaeditor.view.editors.attributetype; import java.util.Comparator; import org.apache.directory.api.ldap.model.schema.LdapSyntax; import org.apache.directory.studio.schemaeditor.view.editors.NonExistingSyntax; /** * This class implements the Comparator used to compare elements in the Matching Rules Content Providers. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class ATESyntaxComboComparator implements Comparator<Object> { /** * {@inheritDoc} */ public int compare( Object o1, Object o2 ) { String syntax1Description = null; String syntax2Description = null; if ( o1 instanceof LdapSyntax && o2 instanceof LdapSyntax ) { syntax1Description = ( ( LdapSyntax ) o1 ).getDescription(); syntax2Description = ( ( LdapSyntax ) o2 ).getDescription(); } else if ( o1 instanceof LdapSyntax && o2 instanceof NonExistingSyntax ) { syntax1Description = ( ( LdapSyntax ) o1 ).getDescription(); syntax2Description = ( ( NonExistingSyntax ) o2 ).getDescription(); } else if ( o1 instanceof NonExistingSyntax && o2 instanceof LdapSyntax ) { syntax1Description = ( ( NonExistingSyntax ) o1 ).getDescription(); syntax2Description = ( ( LdapSyntax ) o2 ).getDescription(); } else if ( o1 instanceof NonExistingSyntax && o2 instanceof NonExistingSyntax ) { syntax1Description = ( ( NonExistingSyntax ) o1 ).getDescription(); syntax2Description = ( ( NonExistingSyntax ) o2 ).getDescription(); } if ( ( syntax1Description != null ) && ( syntax2Description != null ) ) { return syntax1Description.compareToIgnoreCase( syntax2Description ); } return 0; } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/editors/attributetype/ATEUsedByOptionalTableContentProvider.java
plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/editors/attributetype/ATEUsedByOptionalTableContentProvider.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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.apache.directory.studio.schemaeditor.view.editors.attributetype; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.List; import org.apache.directory.api.ldap.model.schema.AttributeType; import org.apache.directory.api.ldap.model.schema.ObjectClass; import org.apache.directory.api.util.Strings; import org.apache.directory.studio.schemaeditor.Activator; import org.apache.directory.studio.schemaeditor.controller.SchemaHandler; import org.eclipse.jface.viewers.IStructuredContentProvider; import org.eclipse.jface.viewers.Viewer; /** * This class is the Content Provider for the Optional Table of the Attribute Type Editor (Used By Page). * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class ATEUsedByOptionalTableContentProvider implements IStructuredContentProvider { /** * {@inheritDoc} */ public Object[] getElements( Object inputElement ) { if ( inputElement instanceof AttributeType ) { List<ObjectClass> results = new ArrayList<ObjectClass>(); AttributeType inputAT = ( AttributeType ) inputElement; SchemaHandler schemaHandler = Activator.getDefault().getSchemaHandler(); List<String> names = new ArrayList<String>(); List<String> atNames = inputAT.getNames(); if ( atNames != null ) { for ( String name : atNames ) { names.add( Strings.toLowerCase( name ) ); } } List<ObjectClass> objectClasses = schemaHandler.getObjectClasses(); for ( ObjectClass oc : objectClasses ) { List<String> mays = oc.getMayAttributeTypeOids(); if ( mays != null ) { for ( String may : mays ) { if ( names.contains( Strings.toLowerCase( may ) ) ) { results.add( oc ); } } } } // Sorting Results Collections.sort( results, new Comparator<ObjectClass>() { public int compare( ObjectClass oc1, ObjectClass oc2 ) { if ( oc1 instanceof ObjectClass && oc1 instanceof ObjectClass ) { List<String> oc1Names = ( ( ObjectClass ) oc1 ).getNames(); List<String> oc2Names = ( ( ObjectClass ) oc2 ).getNames(); if ( ( oc1Names != null ) && ( oc2Names != null ) && ( oc1Names.size() > 0 ) && ( oc2Names.size() > 0 ) ) { return oc1Names.get( 0 ).compareToIgnoreCase( oc2Names.get( 0 ) ); } } return 0; } } ); return results.toArray(); } // Default return null; } /** * {@inheritDoc} */ public void dispose() { } /** * {@inheritDoc} */ public void inputChanged( Viewer viewer, Object oldInput, Object newInput ) { } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/editors/attributetype/AttributeTypeEditor.java
plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/editors/attributetype/AttributeTypeEditor.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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.apache.directory.studio.schemaeditor.view.editors.attributetype; import org.apache.directory.api.ldap.model.schema.AttributeType; import org.apache.directory.studio.schemaeditor.Activator; import org.apache.directory.studio.schemaeditor.PluginConstants; import org.apache.directory.studio.schemaeditor.PluginUtils; import org.apache.directory.studio.schemaeditor.controller.SchemaHandler; import org.apache.directory.studio.schemaeditor.controller.SchemaHandlerAdapter; import org.apache.directory.studio.schemaeditor.controller.SchemaHandlerListener; import org.apache.directory.studio.schemaeditor.model.Schema; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.jface.dialogs.IPageChangedListener; import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.jface.dialogs.PageChangedEvent; import org.eclipse.ui.IEditorInput; import org.eclipse.ui.IEditorSite; import org.eclipse.ui.PartInitException; import org.eclipse.ui.PlatformUI; import org.eclipse.ui.forms.editor.FormEditor; /** * This class represent the Attribute Type Editor. * <p> * It is used to edit the values of an attribute type. */ public class AttributeTypeEditor extends FormEditor { /** The ID of the Editor */ public static final String ID = PluginConstants.EDITOR_ATTRIBUTE_TYPE_ID; /** The editor */ private AttributeTypeEditor instance; /** The dirty state flag */ private boolean dirty = false; // The pages private AttributeTypeEditorOverviewPage overviewPage; private AttributeTypeEditorSourceCodePage sourceCodePage; private AttributeTypeEditorUsedByPage usedByPage; /** The original attribute type */ private AttributeType originalAttributeType; /** The attribute type used to save modifications */ private AttributeType modifiedAttributeType; /** The originalSchema */ private Schema originalSchema; /** The listener for page changed */ private IPageChangedListener pageChangedListener = new IPageChangedListener() { public void pageChanged( PageChangedEvent event ) { Object selectedPage = event.getSelectedPage(); if ( selectedPage instanceof AttributeTypeEditorOverviewPage ) { if ( !sourceCodePage.canLeaveThePage() ) { notifyError( Messages.getString( "AttributeTypeEditor.CodeErrors" ) ); //$NON-NLS-1$ return; } overviewPage.refreshUI(); } else if ( selectedPage instanceof AttributeTypeEditorSourceCodePage ) { if ( sourceCodePage.canLeaveThePage() ) { sourceCodePage.refreshUI(); } } } }; /** The SchemaHandler listener */ private SchemaHandlerListener schemaHandlerListener = new SchemaHandlerAdapter() { public void attributeTypeModified( AttributeType at ) { if ( at.equals( originalAttributeType ) ) { // Updating the modified attribute type modifiedAttributeType = PluginUtils.getClone( originalAttributeType ); // Refreshing the editor pages overviewPage.refreshUI(); sourceCodePage.refreshUI(); usedByPage.refreshUI(); // Refreshing the part name (in case of a change in the name) setPartName( getEditorInput().getName() ); } } public void attributeTypeRemoved( AttributeType at ) { if ( at.equals( originalAttributeType ) ) { getEditorSite().getPage().closeEditor( instance, false ); } } public void schemaRemoved( Schema schema ) { if ( schema.equals( originalSchema ) ) { getEditorSite().getPage().closeEditor( instance, false ); } } public void schemaRenamed( Schema schema ) { if ( schema.equals( originalSchema ) ) { // Updating the modified attribute type modifiedAttributeType = PluginUtils.getClone( originalAttributeType ); // Refreshing the editor pages overviewPage.refreshUI(); sourceCodePage.refreshUI(); usedByPage.refreshUI(); } } }; /** * {@inheritDoc} */ public void init( IEditorSite site, IEditorInput input ) throws PartInitException { super.init( site, input ); instance = this; setSite( site ); setInput( input ); setPartName( input.getName() ); originalAttributeType = ( AttributeType ) ( ( AttributeTypeEditorInput ) getEditorInput() ) .getAttributeType(); modifiedAttributeType = PluginUtils.getClone( originalAttributeType ); SchemaHandler schemaHandler = Activator.getDefault().getSchemaHandler(); originalSchema = schemaHandler.getSchema( originalAttributeType.getSchemaName() ); schemaHandler.addListener( schemaHandlerListener ); addPageChangedListener( pageChangedListener ); } /** * {@inheritDoc} */ public void dispose() { SchemaHandler schemaHandler = Activator.getDefault().getSchemaHandler(); schemaHandler.removeListener( schemaHandlerListener ); super.dispose(); } /** * {@inheritDoc} */ protected void addPages() { try { overviewPage = new AttributeTypeEditorOverviewPage( this ); addPage( overviewPage ); sourceCodePage = new AttributeTypeEditorSourceCodePage( this ); addPage( sourceCodePage ); usedByPage = new AttributeTypeEditorUsedByPage( this ); addPage( usedByPage ); } catch ( PartInitException e ) { PluginUtils.logError( "error when adding pages", e ); //$NON-NLS-1$ } } /** * {@inheritDoc} */ public void doSave( IProgressMonitor monitor ) { // Verifying if there is an error on the source code page if ( !sourceCodePage.canLeaveThePage() ) { notifyError( Messages.getString( "AttributeTypeEditor.AttributeErrors" ) ); //$NON-NLS-1$ monitor.setCanceled( true ); return; } Activator.getDefault().getSchemaHandler().modifyAttributeType( originalAttributeType, modifiedAttributeType ); setPartName( getEditorInput().getName() ); if ( !monitor.isCanceled() ) { setDirty( false ); } } /** * {@inheritDoc} */ public void doSaveAs() { // Nothing to do. } /** * {@inheritDoc} */ public boolean isSaveAsAllowed() { return false; } /** * {@inheritDoc} */ public boolean isDirty() { return this.dirty; } /** * Sets the dirty state of the editor * * @param dirty * the dirty state */ public void setDirty( boolean dirty ) { this.dirty = dirty; editorDirtyStateChanged(); } /** * Gets the original attribute type. * * @return * the original attribute type */ public AttributeType getOriginalAttributeType() { return originalAttributeType; } /** * Gets the modified attribute type. * * @return * the modified attribute type */ public AttributeType getModifiedAttributeType() { return modifiedAttributeType; } /** * Sets the modified attribute type. * * @param modifiedAttributeType * the modified attribute type to set. */ public void setModifiedAttributeType( AttributeType modifiedAttributeType ) { this.modifiedAttributeType = modifiedAttributeType; } /** * Opens an error dialog displaying the given message. * * @param message * the message to display */ private void notifyError( String message ) { MessageDialog.openError( PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), Messages.getString( "AttributeTypeEditor.Error" ), message ); //$NON-NLS-1$ } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/editors/attributetype/ATESuperiorComboComparator.java
plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/editors/attributetype/ATESuperiorComboComparator.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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.apache.directory.studio.schemaeditor.view.editors.attributetype; import java.util.Comparator; import java.util.List; import org.apache.directory.api.ldap.model.schema.AttributeType; import org.apache.directory.studio.schemaeditor.view.editors.NonExistingAttributeType; /** * This class implements the Comparator used to compare elements in the Matching Rules Content Providers. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class ATESuperiorComboComparator implements Comparator<Object> { /** * {@inheritDoc} */ public int compare( Object o1, Object o2 ) { if ( o1 instanceof AttributeType && o2 instanceof AttributeType ) { List<String> at1Names = ( ( AttributeType ) o1 ).getNames(); List<String> at2Names = ( ( AttributeType ) o2 ).getNames(); if ( ( at1Names != null ) && ( at2Names != null ) && ( at1Names.size() > 0 ) && ( at2Names.size() > 0 ) ) { return at1Names.get( 0 ).compareToIgnoreCase( at2Names.get( 0 ) ); } } else if ( o1 instanceof AttributeType && o2 instanceof NonExistingAttributeType ) { List<String> at1Names = ( ( AttributeType ) o1 ).getNames(); String at2Name = ( ( NonExistingAttributeType ) o2 ).getName(); if ( ( at1Names != null ) && ( at2Name != null ) && ( at1Names.size() > 0 ) ) { return at1Names.get( 0 ).compareToIgnoreCase( at2Name ); } } else if ( o1 instanceof NonExistingAttributeType && o2 instanceof AttributeType ) { String at1Name = ( ( NonExistingAttributeType ) o1 ).getName(); List<String> at2Names = ( ( AttributeType ) o2 ).getNames(); if ( ( at1Name != null ) && ( at2Names != null ) && ( at2Names.size() > 0 ) ) { return at1Name.compareToIgnoreCase( at2Names.get( 0 ) ); } } else if ( o1 instanceof NonExistingAttributeType && o2 instanceof NonExistingAttributeType ) { String at1Name = ( ( NonExistingAttributeType ) o1 ).getName(); String at2Name = ( ( NonExistingAttributeType ) o2 ).getName(); if ( ( at1Name != null ) && ( at2Name != null ) ) { return at1Name.compareToIgnoreCase( at2Name ); } } return 0; } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/editors/attributetype/ATEMatchingRulesComboContentProvider.java
plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/editors/attributetype/ATEMatchingRulesComboContentProvider.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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.apache.directory.studio.schemaeditor.view.editors.attributetype; import java.util.Collections; import java.util.List; import org.apache.directory.api.ldap.model.schema.MatchingRule; import org.apache.directory.studio.schemaeditor.Activator; import org.apache.directory.studio.schemaeditor.view.editors.NonExistingMatchingRule; import org.eclipse.jface.viewers.IStructuredContentProvider; import org.eclipse.jface.viewers.Viewer; /** * This class implements the Content Provider for the Equality Combo of the Attribute Type Editor. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class ATEMatchingRulesComboContentProvider implements IStructuredContentProvider { /** * {@inheritDoc} */ public Object[] getElements( Object inputElement ) { if ( inputElement instanceof ATEMatchingRulesComboInput ) { ATEMatchingRulesComboInput input = ( ATEMatchingRulesComboInput ) inputElement; if ( input.getChildren().isEmpty() ) { // Creating the '(None)' item input.addChild( new NonExistingMatchingRule( NonExistingMatchingRule.NONE ) ); // Creating Children List<MatchingRule> equalityMatchingRules = Activator.getDefault().getSchemaHandler() .getMatchingRules(); for ( MatchingRule matchingRule : equalityMatchingRules ) { input.addChild( matchingRule ); } } // Getting Children List<Object> children = input.getChildren(); // Sorting Children Collections.sort( children, new ATEMatchingRulesComboComparator() ); return children.toArray(); } // Default return new Object[0]; } /** * {@inheritDoc} */ public void dispose() { } /** * {@inheritDoc} */ public void inputChanged( Viewer viewer, Object oldInput, Object newInput ) { } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/editors/attributetype/ATESuperiorComboInput.java
plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/editors/attributetype/ATESuperiorComboInput.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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.apache.directory.studio.schemaeditor.view.editors.attributetype; import java.util.ArrayList; import java.util.List; import org.apache.directory.api.ldap.model.schema.AttributeType; /** * This class implements the Input of the Superior Combo of the Attribute Type Editor * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class ATESuperiorComboInput { /** The attribute type */ private AttributeType at; /** The children */ private List<Object> children; /** * Creates a new instance of ATESuperiorComboInput. * * @param at * the Attribute Type */ public ATESuperiorComboInput( AttributeType at ) { this.at = at; } /** * Gets the Attribute Type. * * @return * the attribute type */ public AttributeType getAttributeType() { return at; } /** * Adds a child. * * @param child * the child to add */ public void addChild( Object child ) { if ( children == null ) { children = new ArrayList<Object>(); } children.add( child ); } /** * Gets the children. * * @return * the children */ public List<Object> getChildren() { if ( children == null ) { children = new ArrayList<Object>(); } return children; } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/editors/attributetype/ATESuperiorComboContentProvider.java
plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/editors/attributetype/ATESuperiorComboContentProvider.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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.apache.directory.studio.schemaeditor.view.editors.attributetype; import java.util.Collections; import java.util.List; import org.apache.directory.api.ldap.model.schema.AttributeType; import org.apache.directory.studio.schemaeditor.Activator; import org.apache.directory.studio.schemaeditor.controller.SchemaHandler; import org.apache.directory.studio.schemaeditor.view.editors.NonExistingAttributeType; import org.eclipse.jface.viewers.IStructuredContentProvider; import org.eclipse.jface.viewers.Viewer; /** * This class implements the Content Provider for the Superior Combo of the Attribute Type Editor. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class ATESuperiorComboContentProvider implements IStructuredContentProvider { /** The Schema Handler */ private SchemaHandler schemaHandler; /** * Creates a new instance of ATESuperiorComboContentProvider. */ public ATESuperiorComboContentProvider() { schemaHandler = Activator.getDefault().getSchemaHandler(); } /** * {@inheritDoc} */ public Object[] getElements( Object inputElement ) { if ( inputElement instanceof ATESuperiorComboInput ) { ATESuperiorComboInput input = ( ATESuperiorComboInput ) inputElement; if ( input.getChildren().isEmpty() ) { AttributeType editorAT = input.getAttributeType(); // Creating the '(None)' item input.addChild( new NonExistingAttributeType( NonExistingAttributeType.NONE ) ); // Creating Children List<AttributeType> ats = schemaHandler.getAttributeTypes(); for ( AttributeType at : ats ) { if ( !isSubType( at, editorAT ) ) { input.addChild( at ); } } } // Getting Children List<Object> children = input.getChildren(); // Sorting Children Collections.sort( children, new ATESuperiorComboComparator() ); return children.toArray(); } // Default return new Object[0]; } /** * {@inheritDoc} */ public void dispose() { } /** * {@inheritDoc} */ public void inputChanged( Viewer viewer, Object oldInput, Object newInput ) { } /** * Checks id an Attribute Type is a sub type of another Attribute Type. * * @param at1 * the first Attribute Type * @param at2 * the second Attribute Type * @return * true if at1 is a sub type of at2 */ private boolean isSubType( AttributeType at1, AttributeType at2 ) { if ( at1.equals( at2 ) ) { return true; } else { String sup = at1.getSuperiorOid(); if ( sup == null ) { return false; } else { AttributeType supAT = schemaHandler.getAttributeType( sup ); if ( supAT == null ) { return false; } else { return isSubType( supAT, at2 ); } } } } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/editors/attributetype/ATEUsedByTablesLabelProvider.java
plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/editors/attributetype/ATEUsedByTablesLabelProvider.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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.apache.directory.studio.schemaeditor.view.editors.attributetype; import org.apache.directory.api.ldap.model.schema.ObjectClass; import org.apache.directory.studio.schemaeditor.Activator; import org.apache.directory.studio.schemaeditor.PluginConstants; import org.apache.directory.studio.schemaeditor.view.ViewUtils; import org.eclipse.jface.viewers.ITableLabelProvider; import org.eclipse.jface.viewers.LabelProvider; import org.eclipse.swt.graphics.Image; /** * This class is the Label Provider for the Used By Tables of the Attribute Type Editor (Used By Page). * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class ATEUsedByTablesLabelProvider extends LabelProvider implements ITableLabelProvider { /** * {@inheritDoc} */ public Image getColumnImage( Object element, int columnIndex ) { if ( element instanceof ObjectClass ) { return Activator.getDefault().getImage( PluginConstants.IMG_OBJECT_CLASS ); } // Default return null; } /** * {@inheritDoc} */ public String getColumnText( Object element, int columnIndex ) { if ( element instanceof ObjectClass ) { return ViewUtils.concateAliases( ( ( ObjectClass ) element ).getNames() ); } // Default return null; } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/editors/attributetype/ATEMatchingRulesComboComparator.java
plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/editors/attributetype/ATEMatchingRulesComboComparator.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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.apache.directory.studio.schemaeditor.view.editors.attributetype; import java.util.Comparator; import java.util.List; import org.apache.directory.api.ldap.model.schema.MatchingRule; import org.apache.directory.studio.schemaeditor.view.editors.NonExistingMatchingRule; /** * This class implements the Comparator used to compare elements in the Matching Rules Content Providers. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class ATEMatchingRulesComboComparator implements Comparator<Object> { /** * {@inheritDoc} */ public int compare( Object o1, Object o2 ) { if ( o1 instanceof MatchingRule && o2 instanceof MatchingRule ) { List<String> mr1Names = ( ( MatchingRule ) o1 ).getNames(); List<String> mr2Names = ( ( MatchingRule ) o2 ).getNames(); if ( ( mr1Names != null ) && ( mr2Names != null ) && ( mr1Names.size() > 0 ) && ( mr2Names.size() > 0 ) ) { return mr1Names.get( 0 ).compareToIgnoreCase( mr2Names.get( 0 ) ); } } else if ( o1 instanceof MatchingRule && o2 instanceof NonExistingMatchingRule ) { List<String> mr1Names = ( ( MatchingRule ) o1 ).getNames(); String mr2Name = ( ( NonExistingMatchingRule ) o2 ).getName(); if ( ( mr1Names != null ) && ( mr2Name != null ) && ( mr1Names.size() > 0 ) ) { return mr1Names.get( 0 ).compareToIgnoreCase( mr2Name ); } } else if ( o1 instanceof NonExistingMatchingRule && o2 instanceof MatchingRule ) { String mr1Name = ( ( NonExistingMatchingRule ) o1 ).getName(); List<String> mr2Names = ( ( MatchingRule ) o2 ).getNames(); if ( ( mr1Name != null ) && ( mr2Names != null ) && ( mr2Names.size() > 0 ) ) { return mr1Name.compareToIgnoreCase( mr2Names.get( 0 ) ); } } else if ( o1 instanceof NonExistingMatchingRule && o2 instanceof NonExistingMatchingRule ) { String mr1Name = ( ( NonExistingMatchingRule ) o1 ).getName(); String mr2Name = ( ( NonExistingMatchingRule ) o2 ).getName(); if ( ( mr1Name != null ) && ( mr2Name != null ) ) { return mr1Name.compareToIgnoreCase( mr2Name ); } } return 0; } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/editors/attributetype/AttributeTypeEditorOverviewPage.java
plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/editors/attributetype/AttributeTypeEditorOverviewPage.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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.apache.directory.studio.schemaeditor.view.editors.attributetype; import java.util.ArrayList; import java.util.List; import org.apache.directory.api.asn1.util.Oid; import org.apache.directory.api.ldap.model.schema.AttributeType; import org.apache.directory.api.ldap.model.schema.LdapSyntax; import org.apache.directory.api.ldap.model.schema.MatchingRule; import org.apache.directory.api.ldap.model.schema.ObjectClass; import org.apache.directory.api.ldap.model.schema.UsageEnum; import org.apache.directory.studio.schemaeditor.Activator; import org.apache.directory.studio.schemaeditor.PluginConstants; import org.apache.directory.studio.schemaeditor.PluginUtils; import org.apache.directory.studio.schemaeditor.controller.SchemaHandler; import org.apache.directory.studio.schemaeditor.controller.SchemaHandlerListener; import org.apache.directory.studio.schemaeditor.model.Schema; import org.apache.directory.studio.schemaeditor.model.alias.Alias; import org.apache.directory.studio.schemaeditor.model.alias.AliasWithError; import org.apache.directory.studio.schemaeditor.model.alias.AliasesStringParser; import org.apache.directory.studio.schemaeditor.view.ViewUtils; import org.apache.directory.studio.schemaeditor.view.dialogs.EditAttributeTypeAliasesDialog; import org.apache.directory.studio.schemaeditor.view.editors.NonExistingAttributeType; import org.apache.directory.studio.schemaeditor.view.editors.NonExistingMatchingRule; import org.apache.directory.studio.schemaeditor.view.editors.NonExistingSyntax; import org.apache.directory.studio.schemaeditor.view.editors.schema.SchemaEditor; import org.apache.directory.studio.schemaeditor.view.editors.schema.SchemaEditorInput; import org.eclipse.jface.viewers.ComboViewer; import org.eclipse.jface.viewers.ISelectionChangedListener; import org.eclipse.jface.viewers.SelectionChangedEvent; import org.eclipse.jface.viewers.StructuredSelection; import org.eclipse.swt.SWT; import org.eclipse.swt.events.ModifyEvent; import org.eclipse.swt.events.ModifyListener; import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.events.VerifyEvent; import org.eclipse.swt.events.VerifyListener; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Combo; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Event; import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Listener; import org.eclipse.swt.widgets.Text; import org.eclipse.ui.IWorkbenchPage; import org.eclipse.ui.PartInitException; import org.eclipse.ui.PlatformUI; import org.eclipse.ui.forms.IManagedForm; import org.eclipse.ui.forms.events.HyperlinkAdapter; import org.eclipse.ui.forms.events.HyperlinkEvent; import org.eclipse.ui.forms.widgets.FormToolkit; import org.eclipse.ui.forms.widgets.Hyperlink; import org.eclipse.ui.forms.widgets.ScrolledForm; import org.eclipse.ui.forms.widgets.Section; /** * This class is the Overview Page of the Attribute Type Editor */ public class AttributeTypeEditorOverviewPage extends AbstractAttributeTypeEditorPage { /** The page ID*/ public static final String ID = AttributeTypeEditor.ID + ".overviewPage"; //$NON-NLS-1$ /** The original schema */ private Schema originalSchema; /** The SchemaHandler */ private SchemaHandler schemaHandler; /** The SchemaHandler Listener */ private SchemaHandlerListener schemaHandlerListener = new SchemaHandlerListener() { public void attributeTypeAdded( AttributeType at ) { refreshUI(); } public void attributeTypeModified( AttributeType at ) { refreshUI(); } public void attributeTypeRemoved( AttributeType at ) { if ( !at.equals( getOriginalAttributeType() ) ) { refreshUI(); } } public void matchingRuleAdded( MatchingRule mr ) { refreshUI(); } public void matchingRuleModified( MatchingRule mr ) { refreshUI(); } public void matchingRuleRemoved( MatchingRule mr ) { refreshUI(); } public void objectClassAdded( ObjectClass oc ) { refreshUI(); } public void objectClassModified( ObjectClass oc ) { refreshUI(); } public void objectClassRemoved( ObjectClass oc ) { refreshUI(); } public void schemaAdded( Schema schema ) { refreshUI(); } public void schemaRemoved( Schema schema ) { if ( !schema.equals( originalSchema ) ) { refreshUI(); } } public void schemaRenamed( Schema schema ) { refreshUI(); } public void syntaxAdded( LdapSyntax syntax ) { refreshUI(); } public void syntaxModified( LdapSyntax syntax ) { refreshUI(); } public void syntaxRemoved( LdapSyntax syntax ) { refreshUI(); } }; // UI Fields private Text aliasesText; private Button aliasesButton; private Text oidText; private Hyperlink schemaLink; private Label schemaLabel; private Text descriptionText; private Hyperlink supLabel; private Combo supCombo; private ComboViewer supComboViewer; private Combo usageCombo; private Combo syntaxCombo; private ComboViewer syntaxComboViewer; private Text syntaxLengthText; private Button obsoleteCheckbox; private Button singleValueCheckbox; private Button collectiveCheckbox; private Button noUserModificationCheckbox; private Combo equalityCombo; private ComboViewer equalityComboViewer; private Combo orderingCombo; private ComboViewer orderingComboViewer; private Combo substringCombo; private ComboViewer substringComboViewer; // Listeners /** The listener for the Aliases Text Widget */ private ModifyListener aliasesTextModifyListener = new ModifyListener() { public void modifyText( ModifyEvent e ) { AttributeType modifiedAttributeType = getModifiedAttributeType(); AliasesStringParser parser = new AliasesStringParser(); parser.parse( aliasesText.getText() ); List<Alias> parsedAliases = parser.getAliases(); modifiedAttributeType.setNames( new String[0] ); List<String> aliasesList = new ArrayList<String>(); for ( Alias parsedAlias : parsedAliases ) { if ( !( parsedAlias instanceof AliasWithError ) ) { aliasesList.add( parsedAlias.getAlias() ); } } modifiedAttributeType.setNames( aliasesList.toArray( new String[0] ) ); setEditorDirty(); } }; /** The listener for the Edit Aliases Button Widget */ private SelectionAdapter aliasesButtonListener = new SelectionAdapter() { public void widgetSelected( SelectionEvent e ) { AttributeType modifiedAttributeType = getModifiedAttributeType(); EditAttributeTypeAliasesDialog dialog = new EditAttributeTypeAliasesDialog( modifiedAttributeType.getNames() ); if ( dialog.open() == EditAttributeTypeAliasesDialog.OK ) { modifiedAttributeType.setNames( dialog.getAliases() ); if ( ( modifiedAttributeType.getNames() != null ) && ( modifiedAttributeType.getNames().size() != 0 ) ) { aliasesText.setText( ViewUtils.concateAliases( modifiedAttributeType.getNames() ) ); } else { aliasesText.setText( "" ); //$NON-NLS-1$ } setEditorDirty(); } } }; /** The Modify listener for the OID Text Widget */ private ModifyListener oidTextModifyListener = new ModifyListener() { public void modifyText( ModifyEvent e ) { oidText.setForeground( ViewUtils.COLOR_BLACK ); oidText.setToolTipText( "" ); //$NON-NLS-1$ String oid = oidText.getText(); if ( Oid.isOid( oid ) ) { if ( ( getOriginalAttributeType().getOid().equals( oid ) ) || !( schemaHandler.isOidAlreadyTaken( oid ) ) ) { getModifiedAttributeType().setOid( oid ); setEditorDirty(); } else { oidText.setForeground( ViewUtils.COLOR_RED ); oidText.setToolTipText( Messages.getString( "AttributeTypeEditorOverviewPage.ElementOIDExists" ) ); //$NON-NLS-1$ } } else { oidText.setForeground( ViewUtils.COLOR_RED ); oidText.setToolTipText( Messages.getString( "AttributeTypeEditorOverviewPage.MalformedOID" ) ); //$NON-NLS-1$ } } }; /** The Verify listener for the OID Text Widget */ private VerifyListener oidTextVerifyListener = new VerifyListener() { public void verifyText( VerifyEvent e ) { if ( !e.text.matches( "([0-9]*\\.?)*" ) ) //$NON-NLS-1$ { e.doit = false; } } }; /** The listener for the Schema Hyperlink Widget*/ private HyperlinkAdapter schemaLinkListener = new HyperlinkAdapter() { public void linkActivated( HyperlinkEvent e ) { IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); SchemaEditorInput input = new SchemaEditorInput( schemaHandler .getSchema( getModifiedAttributeType().getSchemaName() ) ); String editorId = SchemaEditor.ID; try { page.openEditor( input, editorId ); } catch ( PartInitException exception ) { PluginUtils.logError( "error when opening the editor", exception ); //$NON-NLS-1$ } } }; /** The listener for the Description Text Widget */ private ModifyListener descriptionTextListener = new ModifyListener() { public void modifyText( ModifyEvent e ) { int caretPosition = descriptionText.getCaretPosition(); getModifiedAttributeType().setDescription( descriptionText.getText() ); descriptionText.setSelection( caretPosition ); setEditorDirty(); } }; /** The listener for the Sup Label Widget*/ private HyperlinkAdapter supLabelListener = new HyperlinkAdapter() { public void linkActivated( HyperlinkEvent e ) { Object selectedItem = ( ( StructuredSelection ) supComboViewer.getSelection() ).getFirstElement(); if ( selectedItem instanceof AttributeType ) { IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); AttributeTypeEditorInput input = new AttributeTypeEditorInput( ( AttributeType ) selectedItem ); try { page.openEditor( input, AttributeTypeEditor.ID ); } catch ( PartInitException exception ) { PluginUtils.logError( "error when opening the editor", exception ); //$NON-NLS-1$ } } } }; /** The listener for the Sup Combo Widget */ private ISelectionChangedListener supComboViewerListener = new ISelectionChangedListener() { public void selectionChanged( SelectionChangedEvent event ) { AttributeType modifiedAttributeType = getModifiedAttributeType(); Object selectedItem = ( ( StructuredSelection ) supComboViewer.getSelection() ).getFirstElement(); if ( selectedItem instanceof AttributeType ) { AttributeType at = ( AttributeType ) selectedItem; List<String> names = at.getNames(); if ( ( names != null ) && ( names.size() > 0 ) ) { modifiedAttributeType.setSuperiorOid( names.get( 0 ) ); } else { modifiedAttributeType.setSuperiorOid( at.getOid() ); } } else if ( selectedItem instanceof NonExistingAttributeType ) { NonExistingAttributeType neat = ( NonExistingAttributeType ) selectedItem; if ( NonExistingAttributeType.NONE.equals( neat.getName() ) ) { modifiedAttributeType.setSuperiorOid( null ); } else { modifiedAttributeType.setSuperiorOid( ( ( NonExistingAttributeType ) selectedItem ).getName() ); } } setEditorDirty(); } }; /** The listener for the Usage Combo Widget */ private ModifyListener usageComboListener = new ModifyListener() { public void modifyText( ModifyEvent e ) { AttributeType modifiedAttributeType = getModifiedAttributeType(); if ( usageCombo.getSelectionIndex() == 0 ) { modifiedAttributeType.setUsage( UsageEnum.DIRECTORY_OPERATION ); } else if ( usageCombo.getSelectionIndex() == 1 ) { modifiedAttributeType.setUsage( UsageEnum.DISTRIBUTED_OPERATION ); } else if ( usageCombo.getSelectionIndex() == 2 ) { modifiedAttributeType.setUsage( UsageEnum.DSA_OPERATION ); } else if ( usageCombo.getSelectionIndex() == 3 ) { modifiedAttributeType.setUsage( UsageEnum.USER_APPLICATIONS ); } setEditorDirty(); } }; /** The listener for the Syntax Combo Widget */ private ISelectionChangedListener syntaxComboViewerListener = new ISelectionChangedListener() { public void selectionChanged( SelectionChangedEvent event ) { AttributeType modifiedAttributeType = getModifiedAttributeType(); Object selectedItem = ( ( StructuredSelection ) syntaxComboViewer.getSelection() ).getFirstElement(); if ( selectedItem instanceof LdapSyntax ) { modifiedAttributeType.setSyntaxOid( ( ( LdapSyntax ) selectedItem ).getOid() ); } else if ( selectedItem instanceof NonExistingSyntax ) { NonExistingSyntax nes = ( NonExistingSyntax ) selectedItem; if ( NonExistingMatchingRule.NONE.equals( nes.getDescription() ) ) { modifiedAttributeType.setSyntaxOid( null ); } else { modifiedAttributeType.setSyntaxOid( ( ( NonExistingSyntax ) selectedItem ).getDescription() ); } } setEditorDirty(); } }; /** The Modify listener for the Syntax Length Text Widget */ private ModifyListener syntaxLengthTextModifyListener = new ModifyListener() { public void modifyText( ModifyEvent e ) { AttributeType modifiedAttributeType = getModifiedAttributeType(); if ( syntaxLengthText.getText().length() <= 0 ) { modifiedAttributeType.setSyntaxLength( -1 ); } else { modifiedAttributeType.setSyntaxLength( Integer.parseInt( syntaxLengthText.getText() ) ); } setEditorDirty(); } }; /** The Verify listener for the Syntax Length Text Widget */ private VerifyListener syntaxLengthTextVerifyListener = new VerifyListener() { public void verifyText( VerifyEvent e ) { if ( !e.text.matches( "[0-9]*" ) ) //$NON-NLS-1$ { e.doit = false; } } }; /** The listener for the Obsolete Checbox Widget */ private SelectionAdapter obsoleteCheckboxListener = new SelectionAdapter() { public void widgetSelected( SelectionEvent e ) { getModifiedAttributeType().setObsolete( obsoleteCheckbox.getSelection() ); setEditorDirty(); } }; /** The listener for the Single-Value Checkbox Widget */ private SelectionAdapter singleValueCheckboxListener = new SelectionAdapter() { public void widgetSelected( SelectionEvent e ) { getModifiedAttributeType().setSingleValued( singleValueCheckbox.getSelection() ); setEditorDirty(); } }; /** The listener for the Collective Checkbox Widget */ private SelectionAdapter collectiveCheckboxListener = new SelectionAdapter() { public void widgetSelected( SelectionEvent e ) { getModifiedAttributeType().setCollective( collectiveCheckbox.getSelection() ); setEditorDirty(); } }; /** The listener for the No-User-Modification Widget */ private SelectionAdapter noUserModificationCheckboxListener = new SelectionAdapter() { public void widgetSelected( SelectionEvent e ) { getModifiedAttributeType().setUserModifiable( !noUserModificationCheckbox.getSelection() ); setEditorDirty(); } }; /** The listener for the Equality Combo Widget */ private ISelectionChangedListener equalityComboViewerListener = new ISelectionChangedListener() { public void selectionChanged( SelectionChangedEvent event ) { AttributeType modifiedAttributeType = getModifiedAttributeType(); Object selectedItem = ( ( StructuredSelection ) equalityComboViewer.getSelection() ).getFirstElement(); if ( selectedItem instanceof MatchingRule ) { modifiedAttributeType.setEqualityOid( ( ( MatchingRule ) selectedItem ).getName() ); } else if ( selectedItem instanceof NonExistingMatchingRule ) { NonExistingMatchingRule nemr = ( NonExistingMatchingRule ) selectedItem; if ( NonExistingMatchingRule.NONE.equals( nemr.getName() ) ) { modifiedAttributeType.setEqualityOid( null ); } else { modifiedAttributeType.setEqualityOid( ( ( NonExistingMatchingRule ) selectedItem ).getName() ); } } setEditorDirty(); } }; /** The listener for the Ordering Combo Widget */ private ISelectionChangedListener orderingComboViewerListener = new ISelectionChangedListener() { public void selectionChanged( SelectionChangedEvent event ) { AttributeType modifiedAttributeType = getModifiedAttributeType(); Object selectedItem = ( ( StructuredSelection ) orderingComboViewer.getSelection() ).getFirstElement(); if ( selectedItem instanceof MatchingRule ) { modifiedAttributeType.setOrderingOid( ( ( MatchingRule ) selectedItem ).getName() ); } else if ( selectedItem instanceof NonExistingMatchingRule ) { NonExistingMatchingRule nemr = ( NonExistingMatchingRule ) selectedItem; if ( NonExistingMatchingRule.NONE.equals( nemr.getName() ) ) { modifiedAttributeType.setOrderingOid( null ); } else { modifiedAttributeType.setOrderingOid( ( ( NonExistingMatchingRule ) selectedItem ).getName() ); } } setEditorDirty(); } }; /** The listener for the Substring Combo Widget */ private ISelectionChangedListener substringComboViewerListener = new ISelectionChangedListener() { public void selectionChanged( SelectionChangedEvent event ) { AttributeType modifiedAttributeType = getModifiedAttributeType(); Object selectedItem = ( ( StructuredSelection ) substringComboViewer.getSelection() ).getFirstElement(); if ( selectedItem instanceof MatchingRule ) { modifiedAttributeType.setSubstringOid( ( ( MatchingRule ) selectedItem ).getName() ); } else if ( selectedItem instanceof NonExistingMatchingRule ) { NonExistingMatchingRule nemr = ( NonExistingMatchingRule ) selectedItem; if ( NonExistingMatchingRule.NONE.equals( nemr.getName() ) ) { modifiedAttributeType.setSubstringOid( null ); } else { modifiedAttributeType.setSubstringOid( ( ( NonExistingMatchingRule ) selectedItem ).getName() ); } } setEditorDirty(); } }; /** The filter listener for Mouse Wheel events */ private Listener mouseWheelFilter = new Listener() { public void handleEvent( Event event ) { // Hiding Mouse Wheel events for Combo widgets if ( event.widget instanceof Combo ) { event.doit = false; } } }; /** * Default constructor. * * @param editor * the associated editor */ public AttributeTypeEditorOverviewPage( AttributeTypeEditor editor ) { super( editor, ID, Messages.getString( "AttributeTypeEditorOverviewPage.Overview" ) ); //$NON-NLS-1$ schemaHandler = Activator.getDefault().getSchemaHandler(); schemaHandler.addListener( schemaHandlerListener ); } /** * {@inheritDoc} */ protected void createFormContent( IManagedForm managedForm ) { super.createFormContent( managedForm ); // Creating the base UI ScrolledForm form = managedForm.getForm(); FormToolkit toolkit = managedForm.getToolkit(); GridLayout layout = new GridLayout(); form.getBody().setLayout( layout ); // General Information Section createGeneralInformationSection( form.getBody(), toolkit ); // Matching Rules Section createMatchingRulesSection( form.getBody(), toolkit ); // Filling the UI with values from the attribute type fillInUiFields(); // Listeners initialization addListeners(); // Help Context for Dynamic Help PlatformUI.getWorkbench().getHelpSystem().setHelp( form, PluginConstants.PLUGIN_ID + "." + "attribute_type_editor" ); //$NON-NLS-1$ //$NON-NLS-2$ } /** * Creates the General Information Section. * * @param parent * the parent composite * @param toolkit * the FormToolKit to use */ private void createGeneralInformationSection( Composite parent, FormToolkit toolkit ) { // General Information Section Section section_general_information = toolkit.createSection( parent, Section.DESCRIPTION | Section.EXPANDED | Section.TITLE_BAR ); section_general_information.setDescription( Messages .getString( "AttributeTypeEditorOverviewPage.SpecifyGeneralInformation" ) ); //$NON-NLS-1$ section_general_information .setText( Messages.getString( "AttributeTypeEditorOverviewPage.GeneralInformation" ) ); //$NON-NLS-1$ // Creating the layout of the section Composite client_general_information = toolkit.createComposite( section_general_information ); client_general_information.setLayout( new GridLayout( 2, false ) ); toolkit.paintBordersFor( client_general_information ); section_general_information.setClient( client_general_information ); section_general_information.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) ); // Adding elements to the section // ALIASES Field toolkit .createLabel( client_general_information, Messages.getString( "AttributeTypeEditorOverviewPage.Aliases" ) ); //$NON-NLS-1$ Composite aliasComposite = toolkit.createComposite( client_general_information ); GridLayout aliasCompositeGridLayout = new GridLayout( 2, false ); toolkit.paintBordersFor( aliasComposite ); aliasCompositeGridLayout.marginHeight = 1; aliasCompositeGridLayout.marginWidth = 1; aliasComposite.setLayout( aliasCompositeGridLayout ); aliasComposite.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) ); aliasesText = toolkit.createText( aliasComposite, "" ); //$NON-NLS-1$ aliasesText.setLayoutData( new GridData( SWT.FILL, SWT.CENTER, true, false ) ); aliasesButton = toolkit.createButton( aliasComposite, Messages .getString( "AttributeTypeEditorOverviewPage.EditAliases" ), SWT.PUSH ); //$NON-NLS-1$ aliasesButton.setLayoutData( new GridData( SWT.NONE, SWT.CENTER, false, false ) ); // OID Field toolkit.createLabel( client_general_information, Messages.getString( "AttributeTypeEditorOverviewPage.OID" ) ); //$NON-NLS-1$ oidText = toolkit.createText( client_general_information, "" ); //$NON-NLS-1$ oidText.setLayoutData( new GridData( SWT.FILL, 0, true, false ) ); // DESCRIPTION Field toolkit.createLabel( client_general_information, Messages .getString( "AttributeTypeEditorOverviewPage.Description" ) ); //$NON-NLS-1$ descriptionText = toolkit.createText( client_general_information, "", SWT.MULTI | SWT.V_SCROLL ); //$NON-NLS-1$ GridData descriptionGridData = new GridData( SWT.FILL, SWT.NONE, true, false ); descriptionGridData.heightHint = 42; descriptionText.setLayoutData( descriptionGridData ); // SCHEMA Field schemaLink = toolkit.createHyperlink( client_general_information, Messages .getString( "AttributeTypeEditorOverviewPage.Schema" ), SWT.WRAP ); //$NON-NLS-1$ schemaLabel = toolkit.createLabel( client_general_information, "" ); //$NON-NLS-1$ schemaLabel.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) ); // SUP Combo supLabel = toolkit.createHyperlink( client_general_information, Messages .getString( "AttributeTypeEditorOverviewPage.SuperiorType" ), SWT.WRAP ); //$NON-NLS-1$ supCombo = new Combo( client_general_information, SWT.READ_ONLY | SWT.SINGLE ); supCombo.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) ); supComboViewer = new ComboViewer( supCombo ); supComboViewer.setContentProvider( new ATESuperiorComboContentProvider() ); supComboViewer.setLabelProvider( new ATESuperiorComboLabelProvider() ); // USAGE Combo toolkit.createLabel( client_general_information, Messages.getString( "AttributeTypeEditorOverviewPage.Usage" ) ); //$NON-NLS-1$ usageCombo = new Combo( client_general_information, SWT.READ_ONLY | SWT.SINGLE ); usageCombo.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) ); initUsageCombo(); // SYNTAX Combo toolkit .createLabel( client_general_information, Messages.getString( "AttributeTypeEditorOverviewPage.Syntax" ) ); //$NON-NLS-1$ syntaxCombo = new Combo( client_general_information, SWT.READ_ONLY | SWT.SINGLE ); syntaxCombo.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) ); syntaxComboViewer = new ComboViewer( syntaxCombo ); syntaxComboViewer.setContentProvider( new ATESyntaxComboContentProvider() ); syntaxComboViewer.setLabelProvider( new ATESyntaxComboLabelProvider() ); // SYNTAX LENGTH Field toolkit.createLabel( client_general_information, Messages .getString( "AttributeTypeEditorOverviewPage.SyntaxLength" ) ); //$NON-NLS-1$ syntaxLengthText = toolkit.createText( client_general_information, "" ); //$NON-NLS-1$ syntaxLengthText.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) ); // PROPERTIES composite toolkit.createLabel( client_general_information, "" ); // Filling the first column //$NON-NLS-1$ Composite propertiesComposite = toolkit.createComposite( client_general_information ); GridLayout propertiesCompositeGridLayout = new GridLayout( 2, true ); propertiesCompositeGridLayout.horizontalSpacing = 0; propertiesCompositeGridLayout.verticalSpacing = 0; propertiesCompositeGridLayout.marginHeight = 0; propertiesCompositeGridLayout.marginWidth = 0; propertiesComposite.setLayout( propertiesCompositeGridLayout ); propertiesComposite.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) ); // OBSOLETE Checkbox obsoleteCheckbox = toolkit.createButton( propertiesComposite, Messages .getString( "AttributeTypeEditorOverviewPage.Obsolete" ), SWT.CHECK ); //$NON-NLS-1$ obsoleteCheckbox.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) ); // SINGLE-VALUE Checkbox singleValueCheckbox = toolkit.createButton( propertiesComposite, Messages .getString( "AttributeTypeEditorOverviewPage.SingleValue" ), SWT.CHECK ); //$NON-NLS-1$ singleValueCheckbox.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) ); // COLLECTIVE Checkbox toolkit.createLabel( client_general_information, "" ); // Filling the first column //$NON-NLS-1$ collectiveCheckbox = toolkit.createButton( propertiesComposite, Messages .getString( "AttributeTypeEditorOverviewPage.Collective" ), SWT.CHECK ); //$NON-NLS-1$ collectiveCheckbox.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) ); // NO-USER-MODIFICATION Checkbox noUserModificationCheckbox = toolkit.createButton( propertiesComposite, Messages.getString( "AttributeTypeEditorOverviewPage.NoUserModification" ), SWT.CHECK ); //$NON-NLS-1$ noUserModificationCheckbox.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) ); } /** * Creates the Matching Rules Section. * * @param parent * the parent composite * @param toolkit * the FormToolKit to use */ private void createMatchingRulesSection( Composite parent, FormToolkit toolkit ) { // Matching Rules Section Section section_matching_rules = toolkit.createSection( parent, Section.DESCRIPTION | Section.EXPANDED | Section.TITLE_BAR ); section_matching_rules.setDescription( Messages .getString( "AttributeTypeEditorOverviewPage.SpecifyMatchingRules" ) ); //$NON-NLS-1$ section_matching_rules.setText( Messages.getString( "AttributeTypeEditorOverviewPage.MatchingRules" ) ); //$NON-NLS-1$ // Creating the layout of the section Composite client_matching_rules = toolkit.createComposite( section_matching_rules ); GridLayout layout_matching_rules = new GridLayout(); layout_matching_rules.numColumns = 2;
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
true
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/editors/attributetype/AttributeTypeEditorUsedByPage.java
plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/editors/attributetype/AttributeTypeEditorUsedByPage.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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.apache.directory.studio.schemaeditor.view.editors.attributetype; import java.util.List; import org.apache.directory.api.ldap.model.schema.AttributeType; import org.apache.directory.api.ldap.model.schema.ObjectClass; import org.apache.directory.studio.schemaeditor.Activator; import org.apache.directory.studio.schemaeditor.PluginConstants; import org.apache.directory.studio.schemaeditor.PluginUtils; import org.apache.directory.studio.schemaeditor.controller.SchemaHandlerAdapter; import org.apache.directory.studio.schemaeditor.controller.SchemaHandlerListener; import org.apache.directory.studio.schemaeditor.model.Schema; import org.apache.directory.studio.schemaeditor.view.ViewUtils; import org.apache.directory.studio.schemaeditor.view.editors.objectclass.ObjectClassEditor; import org.apache.directory.studio.schemaeditor.view.editors.objectclass.ObjectClassEditorInput; import org.eclipse.jface.viewers.StructuredSelection; import org.eclipse.jface.viewers.TableViewer; import org.eclipse.osgi.util.NLS; import org.eclipse.swt.SWT; import org.eclipse.swt.events.MouseAdapter; import org.eclipse.swt.events.MouseEvent; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Table; import org.eclipse.ui.IWorkbenchPage; import org.eclipse.ui.PartInitException; import org.eclipse.ui.PlatformUI; import org.eclipse.ui.forms.IManagedForm; import org.eclipse.ui.forms.widgets.FormToolkit; import org.eclipse.ui.forms.widgets.ScrolledForm; import org.eclipse.ui.forms.widgets.Section; /** * This class is the Used By Page of the Attribute Type Editor */ public class AttributeTypeEditorUsedByPage extends AbstractAttributeTypeEditorPage { /** The page ID */ public static final String ID = AttributeTypeEditor.ID + "usedByPage"; //$NON-NLS-1$ /** The Schema listener */ private SchemaHandlerListener schemaHandlerListener = new SchemaHandlerAdapter() { /** * {@inheritDoc} */ public void attributeTypeAdded( AttributeType at ) { refreshTableViewers(); } /** * {@inheritDoc} */ public void attributeTypeModified( AttributeType at ) { refreshTableViewers(); } /** * {@inheritDoc} */ public void attributeTypeRemoved( AttributeType at ) { refreshTableViewers(); } /** * {@inheritDoc} */ public void objectClassAdded( ObjectClass oc ) { refreshTableViewers(); } /** * {@inheritDoc} */ public void objectClassModified( ObjectClass oc ) { refreshTableViewers(); } /** * {@inheritDoc} */ public void objectClassRemoved( ObjectClass oc ) { refreshTableViewers(); } /** * {@inheritDoc} */ public void schemaAdded( Schema schema ) { refreshTableViewers(); } /** * {@inheritDoc} */ public void schemaRemoved( Schema schema ) { refreshTableViewers(); } }; // UI Widgets private Table mandatoryAttributeTable; private TableViewer mandatoryAttributeTableViewer; private Table optionalAttibuteTable; private TableViewer optionalAttibuteTableViewer; // Listeners /** The listener of the Mandatory Attribute Type Table*/ private MouseAdapter mandatoryAttributeTableListener = new MouseAdapter() { public void mouseDoubleClick( MouseEvent e ) { Object selectedItem = ( ( StructuredSelection ) mandatoryAttributeTableViewer.getSelection() ) .getFirstElement(); if ( selectedItem instanceof ObjectClass ) { IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); try { page.openEditor( new ObjectClassEditorInput( ( ObjectClass ) selectedItem ), ObjectClassEditor.ID ); } catch ( PartInitException exception ) { PluginUtils.logError( "error when opening the editor", exception ); //$NON-NLS-1$ } } } }; /** The listener of the Optional Attribute Type Table*/ private MouseAdapter optionalAttibuteTableListener = new MouseAdapter() { public void mouseDoubleClick( MouseEvent e ) { Object selectedItem = ( ( StructuredSelection ) optionalAttibuteTableViewer.getSelection() ) .getFirstElement(); if ( selectedItem instanceof ObjectClass ) { IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); try { page.openEditor( new ObjectClassEditorInput( ( ObjectClass ) selectedItem ), ObjectClassEditor.ID ); } catch ( PartInitException exception ) { PluginUtils.logError( "error when opening the editor", exception ); //$NON-NLS-1$ } } } }; /** * Default constructor. * * @param editor * the associated editor */ public AttributeTypeEditorUsedByPage( AttributeTypeEditor editor ) { super( editor, ID, Messages.getString( "AttributeTypeEditorUsedByPage.UsedBy" ) ); //$NON-NLS-1$ Activator.getDefault().getSchemaHandler().addListener( schemaHandlerListener ); } /** * {@inheritDoc} */ protected void createFormContent( IManagedForm managedForm ) { // Creating the base UI ScrolledForm form = managedForm.getForm(); FormToolkit toolkit = managedForm.getToolkit(); GridLayout layout = new GridLayout( 2, true ); form.getBody().setLayout( layout ); // As Mandatory Attribute Section createAsMandatoryAttributeSection( form.getBody(), toolkit ); // As Optional Attribute Section createAsOptionalAttributeSection( form.getBody(), toolkit ); // Filling the UI with values from the attribute type fillInUiFields(); // Listeners initialization addListeners(); // Help Context for Dynamic Help PlatformUI.getWorkbench().getHelpSystem().setHelp( form, PluginConstants.PLUGIN_ID + "." + "attribute_type_editor" ); //$NON-NLS-1$ //$NON-NLS-2$ initialized = true; } /** * Creates the As Mandatory Attribute Section. * * @param parent * the parent composite * @param toolkit * the FormToolKit to use */ private void createAsMandatoryAttributeSection( Composite parent, FormToolkit toolkit ) { AttributeType modifiedAttributeType = getModifiedAttributeType(); // As Mandatory Attribute Section Section mandatoryAttributeSection = toolkit.createSection( parent, Section.DESCRIPTION | Section.EXPANDED | Section.TITLE_BAR ); List<String> names = modifiedAttributeType.getNames(); if ( ( names != null ) && ( names.size() > 0 ) ) { mandatoryAttributeSection .setDescription( NLS .bind( Messages.getString( "AttributeTypeEditorUsedByPage.AttributeTypeMandatory" ), new String[] { ViewUtils.concateAliases( names ) } ) ); //$NON-NLS-1$ } else { mandatoryAttributeSection .setDescription( NLS .bind( Messages.getString( "AttributeTypeEditorUsedByPage.AttributeTypeMandatory" ), new String[] { modifiedAttributeType.getOid() } ) ); //$NON-NLS-1$ } mandatoryAttributeSection.setText( Messages.getString( "AttributeTypeEditorUsedByPage.AsMandatoryAttribute" ) ); //$NON-NLS-1$ // Creating the layout of the section Composite mandatoryAttributeSectionClient = toolkit.createComposite( mandatoryAttributeSection ); mandatoryAttributeSectionClient.setLayout( new GridLayout() ); toolkit.paintBordersFor( mandatoryAttributeSectionClient ); mandatoryAttributeSection.setClient( mandatoryAttributeSectionClient ); mandatoryAttributeSection.setLayoutData( new GridData( SWT.FILL, SWT.FILL, true, true ) ); mandatoryAttributeTable = toolkit.createTable( mandatoryAttributeSectionClient, SWT.NONE ); GridData gridData = new GridData( SWT.FILL, SWT.FILL, true, true ); gridData.heightHint = 1; mandatoryAttributeTable.setLayoutData( gridData ); mandatoryAttributeTableViewer = new TableViewer( mandatoryAttributeTable ); mandatoryAttributeTableViewer.setContentProvider( new ATEUsedByMandatoryTableContentProvider() ); mandatoryAttributeTableViewer.setLabelProvider( new ATEUsedByTablesLabelProvider() ); } /** * Creates the As Optional Attribute Section. * * @param parent * the parent composite * @param toolkit * the FormToolKit to use */ private void createAsOptionalAttributeSection( Composite parent, FormToolkit toolkit ) { AttributeType modifiedAttributeType = getModifiedAttributeType(); // Matching Rules Section Section optionalAttributeSection = toolkit.createSection( parent, Section.DESCRIPTION | Section.EXPANDED | Section.TITLE_BAR ); List<String> names = modifiedAttributeType.getNames(); if ( ( names != null ) && ( names.size() > 0 ) ) { optionalAttributeSection .setDescription( NLS .bind( Messages.getString( "AttributeTypeEditorUsedByPage.AttributeTypeOptional" ), new String[] { ViewUtils.concateAliases( names ) } ) ); //$NON-NLS-1$ } else { optionalAttributeSection .setDescription( NLS .bind( Messages.getString( "AttributeTypeEditorUsedByPage.AttributeTypeOptional" ), new String[] { modifiedAttributeType.getOid() } ) ); //$NON-NLS-1$ } optionalAttributeSection.setText( Messages.getString( "AttributeTypeEditorUsedByPage.AsOptionalAttribute" ) ); //$NON-NLS-1$ // Creating the layout of the section Composite optionalAttributeSectionClient = toolkit.createComposite( optionalAttributeSection ); optionalAttributeSectionClient.setLayout( new GridLayout() ); toolkit.paintBordersFor( optionalAttributeSectionClient ); optionalAttributeSection.setClient( optionalAttributeSectionClient ); optionalAttributeSection.setLayoutData( new GridData( SWT.FILL, SWT.FILL, true, true ) ); optionalAttibuteTable = toolkit.createTable( optionalAttributeSectionClient, SWT.NONE ); GridData gridData = new GridData( SWT.FILL, SWT.FILL, true, true ); gridData.heightHint = 1; optionalAttibuteTable.setLayoutData( gridData ); optionalAttibuteTableViewer = new TableViewer( optionalAttibuteTable ); optionalAttibuteTableViewer.setContentProvider( new ATEUsedByOptionalTableContentProvider() ); optionalAttibuteTableViewer.setLabelProvider( new ATEUsedByTablesLabelProvider() ); } /** * {@inheritDoc} */ protected void fillInUiFields() { AttributeType modifiedAttributeType = getModifiedAttributeType(); mandatoryAttributeTableViewer.setInput( modifiedAttributeType ); optionalAttibuteTableViewer.setInput( modifiedAttributeType ); } /** * {@inheritDoc} */ protected void addListeners() { addMouseListener( mandatoryAttributeTable, mandatoryAttributeTableListener ); addMouseListener( optionalAttibuteTable, optionalAttibuteTableListener ); } /** * {@inheritDoc} */ protected void removeListeners() { removeMouseListener( mandatoryAttributeTable, mandatoryAttributeTableListener ); removeMouseListener( optionalAttibuteTable, optionalAttibuteTableListener ); } /** * Refreshes the Table Viewers */ public void refreshTableViewers() { if ( mandatoryAttributeTableViewer != null ) { mandatoryAttributeTableViewer.refresh(); } if ( optionalAttibuteTableViewer != null ) { optionalAttibuteTableViewer.refresh(); } } /** * {@inheritDoc} */ public void dispose() { Activator.getDefault().getSchemaHandler().removeListener( schemaHandlerListener ); super.dispose(); } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/editors/attributetype/ATEMatchingRulesComboLabelProvider.java
plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/editors/attributetype/ATEMatchingRulesComboLabelProvider.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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.apache.directory.studio.schemaeditor.view.editors.attributetype; import org.apache.directory.api.ldap.model.schema.MatchingRule; import org.apache.directory.studio.schemaeditor.view.editors.NonExistingMatchingRule; import org.eclipse.jface.viewers.LabelProvider; import org.eclipse.osgi.util.NLS; /** * This class implements the Label Provider of the Matching Rules Combo of the Attribute Type Editor. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class ATEMatchingRulesComboLabelProvider extends LabelProvider { /** * {@inheritDoc} */ public String getText( Object obj ) { if ( obj instanceof MatchingRule ) { MatchingRule mr = ( MatchingRule ) obj; String name = mr.getName(); if ( name != null ) { return name + " - (" + mr.getOid() + ")"; //$NON-NLS-1$ //$NON-NLS-2$ } else { return NLS.bind( Messages.getString( "ATEMatchingRulesComboLabelProvider.None" ), new String[] { mr.getOid() } ); //$NON-NLS-1$ } } else if ( obj instanceof NonExistingMatchingRule ) { return ( ( NonExistingMatchingRule ) obj ).getDisplayName(); } // Default return null; } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/editors/schema/SchemaEditorTableViewerContentProvider.java
plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/editors/schema/SchemaEditorTableViewerContentProvider.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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.apache.directory.studio.schemaeditor.view.editors.schema; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.List; import org.apache.directory.api.ldap.model.schema.AttributeType; import org.apache.directory.api.ldap.model.schema.ObjectClass; import org.eclipse.jface.viewers.IStructuredContentProvider; import org.eclipse.jface.viewers.Viewer; /** * This class is the Content Provider for the Superiors Table of the Object * Class Editor. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class SchemaEditorTableViewerContentProvider implements IStructuredContentProvider { /** * {@inheritDoc} */ public Object[] getElements( Object inputElement ) { if ( inputElement instanceof List<?> ) { List<?> list = ( List<?> ) inputElement; List<Object> results = new ArrayList<Object>(); results.addAll( list ); // Sorting Elements Collections.sort( results, new Comparator<Object>() { public int compare( Object o1, Object o2 ) { if ( o1 instanceof AttributeType && o2 instanceof AttributeType ) { List<String> at1Names = ( ( AttributeType ) o1 ).getNames(); List<String> at2Names = ( ( AttributeType ) o2 ).getNames(); if ( ( at1Names != null ) && ( at2Names != null ) && ( at1Names.size() > 0 ) && ( at2Names.size() > 0 ) ) { return at1Names.get( 0 ).compareToIgnoreCase( at2Names.get( 0 ) ); } } else if ( o1 instanceof ObjectClass && o2 instanceof ObjectClass ) { List<String> oc1Names = ( ( ObjectClass ) o1 ).getNames(); List<String> oc2Names = ( ( ObjectClass ) o2 ).getNames(); if ( ( oc1Names != null ) && ( oc2Names != null ) && ( oc1Names.size() > 0 ) && ( oc2Names.size() > 0 ) ) { return oc1Names.get( 0 ).compareToIgnoreCase( oc2Names.get( 0 ) ); } } return 0; } } ); return results.toArray(); } // Default return null; } /** * {@inheritDoc} */ public void dispose() { } /** * {@inheritDoc} */ public void inputChanged( Viewer viewer, Object oldInput, Object newInput ) { } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/editors/schema/SchemaEditorSourceCodePage.java
plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/editors/schema/SchemaEditorSourceCodePage.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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.apache.directory.studio.schemaeditor.view.editors.schema; import org.apache.directory.api.ldap.model.schema.AttributeType; import org.apache.directory.api.ldap.model.schema.LdapSyntax; import org.apache.directory.api.ldap.model.schema.MatchingRule; import org.apache.directory.api.ldap.model.schema.ObjectClass; import org.apache.directory.studio.schemaeditor.Activator; import org.apache.directory.studio.schemaeditor.PluginConstants; import org.apache.directory.studio.schemaeditor.controller.SchemaHandlerAdapter; import org.apache.directory.studio.schemaeditor.controller.SchemaHandlerListener; import org.apache.directory.studio.schemaeditor.model.Schema; import org.apache.directory.studio.schemaeditor.model.io.OpenLdapSchemaFileExporter; import org.apache.directory.studio.schemaeditor.view.widget.SchemaSourceViewer; import org.eclipse.jface.resource.JFaceResources; import org.eclipse.jface.text.Document; import org.eclipse.jface.text.IDocument; import org.eclipse.swt.SWT; import org.eclipse.swt.graphics.Font; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.ui.PlatformUI; import org.eclipse.ui.forms.IManagedForm; import org.eclipse.ui.forms.editor.FormEditor; import org.eclipse.ui.forms.editor.FormPage; import org.eclipse.ui.forms.widgets.FormToolkit; import org.eclipse.ui.forms.widgets.ScrolledForm; /** * This class is the Source Code Page of the Schema Editor. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class SchemaEditorSourceCodePage extends FormPage { /** The page ID */ public static final String ID = SchemaEditor.ID + "sourceCode"; //$NON-NLS-1$ /** The flag to indicate if the page has been initialized */ private boolean initialized = false; /** The associated schema */ private Schema schema; // UI Field private SchemaSourceViewer schemaSourceViewer; // Listerner private SchemaHandlerListener schemaHandlerListener = new SchemaHandlerAdapter() { /** * {@inheritDoc} */ public void attributeTypeAdded( AttributeType at ) { refreshUI(); } /** * {@inheritDoc} */ public void attributeTypeModified( AttributeType at ) { refreshUI(); } /** * {@inheritDoc} */ public void attributeTypeRemoved( AttributeType at ) { refreshUI(); } /** * {@inheritDoc} */ public void matchingRuleAdded( MatchingRule mr ) { refreshUI(); } /** * {@inheritDoc} */ public void matchingRuleModified( MatchingRule mr ) { refreshUI(); } /** * {@inheritDoc} */ public void matchingRuleRemoved( MatchingRule mr ) { refreshUI(); } /** * {@inheritDoc} */ public void objectClassAdded( ObjectClass oc ) { refreshUI(); } /** * {@inheritDoc} */ public void objectClassModified( ObjectClass oc ) { refreshUI(); } /** * {@inheritDoc} */ public void objectClassRemoved( ObjectClass oc ) { refreshUI(); } /** * {@inheritDoc} */ public void syntaxAdded( LdapSyntax syntax ) { refreshUI(); } /** * {@inheritDoc} */ public void syntaxModified( LdapSyntax syntax ) { refreshUI(); } /** * {@inheritDoc} */ public void syntaxRemoved( LdapSyntax syntax ) { refreshUI(); } }; /** * Creates a new instance of SchemaFormEditorSourceCodePage. * * @param editor * the associated editor */ public SchemaEditorSourceCodePage( FormEditor editor ) { super( editor, ID, Messages.getString( "SchemaEditorSourceCodePage.SourceCode" ) ); //$NON-NLS-1$ Activator.getDefault().getSchemaHandler().addListener( schemaHandlerListener ); } /** * {@inheritDoc} */ protected void createFormContent( IManagedForm managedForm ) { schema = ( ( SchemaEditor ) getEditor() ).getSchema(); ScrolledForm form = managedForm.getForm(); FormToolkit toolkit = managedForm.getToolkit(); GridLayout layout = new GridLayout(); form.getBody().setLayout( layout ); toolkit.paintBordersFor( form.getBody() ); // SOURCE CODE Field schemaSourceViewer = new SchemaSourceViewer( form.getBody(), null, null, false, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL ); GridData gd = new GridData( SWT.FILL, SWT.FILL, true, true ); gd.heightHint = 10; schemaSourceViewer.getTextWidget().setLayoutData( gd ); schemaSourceViewer.getTextWidget().setEditable( false ); // set text font Font font = JFaceResources.getFont( JFaceResources.TEXT_FONT ); schemaSourceViewer.getTextWidget().setFont( font ); IDocument document = new Document(); schemaSourceViewer.setDocument( document ); // Initializes the UI from the schema fillInUiFields(); // Help Context for Dynamic Help PlatformUI.getWorkbench().getHelpSystem().setHelp( form, PluginConstants.PLUGIN_ID + "." + "schema_editor" ); //$NON-NLS-1$ //$NON-NLS-2$ initialized = true; } /** * Fills in the fields of the User Interface. */ private void fillInUiFields() { schemaSourceViewer.getDocument().set( OpenLdapSchemaFileExporter.toSourceCode( schema ) ); } /** * {@inheritDoc} */ public void dispose() { Activator.getDefault().getSchemaHandler().removeListener( schemaHandlerListener ); super.dispose(); } /** * Refreshes the UI. */ public void refreshUI() { if ( initialized ) { fillInUiFields(); } } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/editors/schema/Messages.java
plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/editors/schema/Messages.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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.apache.directory.studio.schemaeditor.view.editors.schema; import java.util.MissingResourceException; import java.util.ResourceBundle; /** * This class get messages from the resources file. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class Messages { /** The resource name */ private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle.getBundle( Messages.class.getPackage().getName() + ".messages" ); /** * Get back a message from the resource file given a key * * @param key The key associated with the message * @return The found message */ public static String getString( String key ) { try { return RESOURCE_BUNDLE.getString( key ); } catch ( MissingResourceException e ) { return '!' + key + '!'; } } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/editors/schema/SchemaEditorTableViewerLabelProvider.java
plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/editors/schema/SchemaEditorTableViewerLabelProvider.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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.apache.directory.studio.schemaeditor.view.editors.schema; import java.util.List; import org.apache.directory.api.ldap.model.schema.AttributeType; import org.apache.directory.api.ldap.model.schema.ObjectClass; import org.apache.directory.studio.schemaeditor.Activator; import org.apache.directory.studio.schemaeditor.PluginConstants; import org.apache.directory.studio.schemaeditor.view.ViewUtils; import org.eclipse.jface.viewers.ITableLabelProvider; import org.eclipse.jface.viewers.LabelProvider; import org.eclipse.osgi.util.NLS; import org.eclipse.swt.graphics.Image; /** * This class is the Label Provider for the TableViewers of the Schema Editor. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class SchemaEditorTableViewerLabelProvider extends LabelProvider implements ITableLabelProvider { /** * {@inheritDoc} */ public Image getColumnImage( Object element, int columnIndex ) { if ( element instanceof ObjectClass ) { return Activator.getDefault().getImage( PluginConstants.IMG_OBJECT_CLASS ); } else if ( element instanceof AttributeType ) { return Activator.getDefault().getImage( PluginConstants.IMG_ATTRIBUTE_TYPE ); } // Default return null; } /** * {@inheritDoc} */ public String getColumnText( Object element, int columnIndex ) { if ( element instanceof ObjectClass ) { ObjectClass oc = ( ObjectClass ) element; List<String> names = oc.getNames(); if ( ( names != null ) && ( names.size() > 0 ) ) { return ViewUtils.concateAliases( names ) + " - (" + oc.getOid() + ")"; //$NON-NLS-1$ //$NON-NLS-2$ } else { return NLS.bind( Messages.getString( "SchemaEditorTableViewerLabelProvider.None" ), new String[] { oc.getOid() } ); //$NON-NLS-1$ } } else if ( element instanceof AttributeType ) { AttributeType at = ( AttributeType ) element; List<String> names = at.getNames(); if ( ( names != null ) && ( names.size() > 0 ) ) { return ViewUtils.concateAliases( names ) + " - (" + at.getOid() + ")"; //$NON-NLS-1$ //$NON-NLS-2$ } else { return NLS.bind( Messages.getString( "SchemaEditorTableViewerLabelProvider.None" ), new String[] { at.getOid() } ); //$NON-NLS-1$ } } // Default return null; } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/editors/schema/SchemaEditor.java
plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/editors/schema/SchemaEditor.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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.apache.directory.studio.schemaeditor.view.editors.schema; import org.apache.directory.studio.schemaeditor.Activator; import org.apache.directory.studio.schemaeditor.PluginConstants; import org.apache.directory.studio.schemaeditor.PluginUtils; import org.apache.directory.studio.schemaeditor.controller.SchemaHandlerAdapter; import org.apache.directory.studio.schemaeditor.controller.SchemaHandlerListener; import org.apache.directory.studio.schemaeditor.model.Schema; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.ui.IEditorInput; import org.eclipse.ui.IEditorSite; import org.eclipse.ui.PartInitException; import org.eclipse.ui.forms.editor.FormEditor; /** * This class is the Schema Editor main class. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class SchemaEditor extends FormEditor { /** The ID of the Editor */ public static final String ID = PluginConstants.EDITOR_SCHEMA_ID; /** The editor */ private SchemaEditor instance; /** The Overview Page */ private SchemaEditorOverviewPage overviewPage; /** The Source Code page */ private SchemaEditorSourceCodePage sourceCodePage; /** The associated schema */ private Schema schema; /** The SchemaHandler listener */ private SchemaHandlerListener schemaHandlerListener = new SchemaHandlerAdapter() { public void schemaRemoved( Schema s ) { if ( schema.equals( s ) ) { getEditorSite().getPage().closeEditor( instance, false ); } } public void schemaRenamed( Schema schema ) { // Refreshing the editor pages overviewPage.refreshUI(); sourceCodePage.refreshUI(); // Refreshing the part name (in case of a change in the name) setPartName( getEditorInput().getName() ); } }; /** * {@inheritDoc} */ public void init( IEditorSite site, IEditorInput input ) throws PartInitException { super.init( site, input ); instance = this; setSite( site ); setInput( input ); setPartName( input.getName() ); schema = ( ( SchemaEditorInput ) getEditorInput() ).getSchema(); Activator.getDefault().getSchemaHandler().addListener( schemaHandlerListener ); } /** * {@inheritDoc} */ protected void addPages() { try { overviewPage = new SchemaEditorOverviewPage( this ); addPage( overviewPage ); sourceCodePage = new SchemaEditorSourceCodePage( this ); addPage( sourceCodePage ); } catch ( PartInitException e ) { PluginUtils.logError( "error when adding pages", e ); //$NON-NLS-1$ } } /** * {@inheritDoc} */ public void dispose() { Activator.getDefault().getSchemaHandler().removeListener( schemaHandlerListener ); super.dispose(); } /** * {@inheritDoc} */ public void doSave( IProgressMonitor monitor ) { // There's nothing to save } /** * {@inheritDoc} */ public void doSaveAs() { } /** * {@inheritDoc} */ public boolean isSaveAsAllowed() { return false; } /** * Gets the associated schema. * * @return * the associated schema */ public Schema getSchema() { return schema; } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/editors/schema/SchemaEditorInput.java
plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/editors/schema/SchemaEditorInput.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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.apache.directory.studio.schemaeditor.view.editors.schema; import org.apache.directory.studio.schemaeditor.model.Schema; import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.ui.IEditorInput; import org.eclipse.ui.IPersistableElement; /** * This class is the Input class for the Schema Editor */ public class SchemaEditorInput implements IEditorInput { private Schema schema; /** * Default constructor * @param schema */ public SchemaEditorInput( Schema schema ) { super(); this.schema = schema; } /** * {@inheritDoc} */ public boolean exists() { return ( this.schema == null ); } /** * {@inheritDoc} */ public ImageDescriptor getImageDescriptor() { return null; } /** * {@inheritDoc} */ public String getName() { return this.schema.getSchemaName(); } /** * {@inheritDoc} */ public IPersistableElement getPersistable() { return null; } /** * {@inheritDoc} */ public String getToolTipText() { return getName(); } /** * {@inheritDoc} */ @SuppressWarnings("rawtypes") public Object getAdapter( Class adapter ) { return null; } /** * {@inheritDoc} */ public boolean equals( Object obj ) { if ( this == obj ) return true; if ( !( obj instanceof SchemaEditorInput ) ) return false; SchemaEditorInput other = ( SchemaEditorInput ) obj; return other.getSchema().equals( this.schema ); } /** * Returns the input schema * @return the input schema */ public Schema getSchema() { return this.schema; } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/editors/schema/SchemaEditorOverviewPage.java
plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/editors/schema/SchemaEditorOverviewPage.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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.apache.directory.studio.schemaeditor.view.editors.schema; import org.apache.directory.api.ldap.model.schema.AttributeType; import org.apache.directory.api.ldap.model.schema.LdapSyntax; import org.apache.directory.api.ldap.model.schema.MatchingRule; import org.apache.directory.api.ldap.model.schema.ObjectClass; import org.apache.directory.studio.schemaeditor.Activator; import org.apache.directory.studio.schemaeditor.PluginConstants; import org.apache.directory.studio.schemaeditor.PluginUtils; import org.apache.directory.studio.schemaeditor.controller.SchemaHandlerAdapter; import org.apache.directory.studio.schemaeditor.controller.SchemaHandlerListener; import org.apache.directory.studio.schemaeditor.model.Schema; import org.apache.directory.studio.schemaeditor.view.ViewUtils; import org.apache.directory.studio.schemaeditor.view.editors.attributetype.AttributeTypeEditor; import org.apache.directory.studio.schemaeditor.view.editors.attributetype.AttributeTypeEditorInput; import org.apache.directory.studio.schemaeditor.view.editors.objectclass.ObjectClassEditor; import org.apache.directory.studio.schemaeditor.view.editors.objectclass.ObjectClassEditorInput; import org.eclipse.jface.viewers.DoubleClickEvent; import org.eclipse.jface.viewers.IDoubleClickListener; import org.eclipse.jface.viewers.StructuredSelection; import org.eclipse.jface.viewers.TableViewer; import org.eclipse.osgi.util.NLS; import org.eclipse.swt.SWT; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Composite; import org.eclipse.ui.PartInitException; import org.eclipse.ui.PlatformUI; import org.eclipse.ui.forms.IManagedForm; import org.eclipse.ui.forms.editor.FormEditor; import org.eclipse.ui.forms.editor.FormPage; import org.eclipse.ui.forms.widgets.FormToolkit; import org.eclipse.ui.forms.widgets.ScrolledForm; import org.eclipse.ui.forms.widgets.Section; /** * This class is the Overview Page of the Schema Editore. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class SchemaEditorOverviewPage extends FormPage { /** The page ID */ public static final String ID = SchemaEditor.ID + "overviewPage"; //$NON-NLS-1$ /** The associated schema */ private Schema originalSchema; private SchemaHandlerListener schemaHandlerListener = new SchemaHandlerAdapter() { public void attributeTypeAdded( AttributeType at ) { refreshUI(); } public void attributeTypeModified( AttributeType at ) { refreshUI(); } public void attributeTypeRemoved( AttributeType at ) { refreshUI(); } public void matchingRuleAdded( MatchingRule mr ) { refreshUI(); } public void matchingRuleModified( MatchingRule mr ) { refreshUI(); } public void matchingRuleRemoved( MatchingRule mr ) { refreshUI(); } public void objectClassAdded( ObjectClass oc ) { refreshUI(); } public void objectClassModified( ObjectClass oc ) { refreshUI(); } public void objectClassRemoved( ObjectClass oc ) { refreshUI(); } public void schemaAdded( Schema schema ) { refreshUI(); } public void schemaRemoved( Schema schema ) { if ( !schema.equals( originalSchema ) ) { refreshUI(); } } public void schemaRenamed( Schema schema ) { refreshUI(); } public void syntaxAdded( LdapSyntax syntax ) { refreshUI(); } public void syntaxModified( LdapSyntax syntax ) { refreshUI(); } public void syntaxRemoved( LdapSyntax syntax ) { refreshUI(); } }; // UI Fields private Section attributeTypesSection; private TableViewer attributeTypesTableViewer; private Section objectClassesSection; private TableViewer objectClassesTableViewer; // Listeners /** The listener of the Attribute Types TableViewer */ private IDoubleClickListener attributeTypesTableViewerListener = new IDoubleClickListener() { /** * {@inheritDoc} */ public void doubleClick( DoubleClickEvent event ) { StructuredSelection selection = ( StructuredSelection ) event.getSelection(); if ( !selection.isEmpty() ) { AttributeType at = ( AttributeType ) selection.getFirstElement(); try { PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().openEditor( new AttributeTypeEditorInput( at ), AttributeTypeEditor.ID ); } catch ( PartInitException exception ) { PluginUtils.logError( Messages.getString( "SchemaEditorOverviewPage.ErrorOpenEditor" ), exception ); //$NON-NLS-1$ ViewUtils.displayErrorMessageDialog( Messages.getString( "SchemaEditorOverviewPage.Error" ), Messages //$NON-NLS-1$ .getString( "SchemaEditorOverviewPage.ErrorOpenEditor" ) ); //$NON-NLS-1$ } } } }; /** The listener of the Object Classes TableViewer */ private IDoubleClickListener objectClassesTableViewerListener = new IDoubleClickListener() { /** * {@inheritDoc} */ public void doubleClick( DoubleClickEvent event ) { StructuredSelection selection = ( StructuredSelection ) event.getSelection(); if ( !selection.isEmpty() ) { ObjectClass oc = ( ObjectClass ) selection.getFirstElement(); try { PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().openEditor( new ObjectClassEditorInput( oc ), ObjectClassEditor.ID ); } catch ( PartInitException exception ) { PluginUtils.logError( Messages.getString( "SchemaEditorOverviewPage.ErrorOpenEditor" ), exception ); //$NON-NLS-1$ ViewUtils.displayErrorMessageDialog( Messages.getString( "SchemaEditorOverviewPage.Error" ), Messages //$NON-NLS-1$ .getString( "SchemaEditorOverviewPage.ErrorOpenEditor" ) ); //$NON-NLS-1$ } } } }; /** * Creates a new instance of SchemaFormEditorOverviewPage. * * @param editor * the associated editor */ public SchemaEditorOverviewPage( FormEditor editor ) { super( editor, ID, Messages.getString( "SchemaEditorOverviewPage.Overview" ) ); //$NON-NLS-1$ Activator.getDefault().getSchemaHandler().addListener( schemaHandlerListener ); } /** * {@inheritDoc} */ protected void createFormContent( IManagedForm managedForm ) { // Getting the associated schema originalSchema = ( ( SchemaEditor ) getEditor() ).getSchema(); // Creating the base UI ScrolledForm form = managedForm.getForm(); FormToolkit toolkit = managedForm.getToolkit(); GridLayout layout = new GridLayout( 2, true ); form.getBody().setLayout( layout ); createAttributeTypesSection( form.getBody(), toolkit ); createObjectClassesSection( form.getBody(), toolkit ); // Initializes the UI from the schema fillInUiFields(); // Listeners initialization addListeners(); // Help Context for Dynamic Help PlatformUI.getWorkbench().getHelpSystem().setHelp( form, PluginConstants.PLUGIN_ID + "." + "schema_editor" ); //$NON-NLS-1$ //$NON-NLS-2$ } /** * Create the Attribute Types Section. * * @param parent * the parent composite * @param toolkit * the FormToolKit to use */ private void createAttributeTypesSection( Composite parent, FormToolkit toolkit ) { // Attribute Types Section attributeTypesSection = toolkit.createSection( parent, Section.DESCRIPTION | Section.EXPANDED | Section.TITLE_BAR ); attributeTypesSection.setDescription( "" ); //$NON-NLS-1$ attributeTypesSection.setText( Messages.getString( "SchemaEditorOverviewPage.AttributeTypes" ) ); //$NON-NLS-1$ // Creating the layout of the section Composite attributeTypesSectionClient = toolkit.createComposite( attributeTypesSection ); attributeTypesSectionClient.setLayout( new GridLayout() ); toolkit.paintBordersFor( attributeTypesSectionClient ); attributeTypesSection.setClient( attributeTypesSectionClient ); attributeTypesSection.setLayoutData( new GridData( SWT.FILL, SWT.FILL, true, true ) ); attributeTypesTableViewer = new TableViewer( attributeTypesSectionClient, SWT.SINGLE | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER ); attributeTypesTableViewer.setContentProvider( new SchemaEditorTableViewerContentProvider() ); attributeTypesTableViewer.setLabelProvider( new SchemaEditorTableViewerLabelProvider() ); attributeTypesTableViewer.getTable().setLayoutData( new GridData( SWT.FILL, SWT.FILL, true, true ) ); } /** * Create the Object Classes Section. * * @param parent * the parent composite * @param toolkit * the FormToolKit to use */ private void createObjectClassesSection( Composite parent, FormToolkit toolkit ) { // Attribute Types Section objectClassesSection = toolkit.createSection( parent, Section.DESCRIPTION | Section.EXPANDED | Section.TITLE_BAR ); objectClassesSection.setDescription( "" );//$NON-NLS-1$ objectClassesSection.setText( Messages.getString( "SchemaEditorOverviewPage.ObjectClasses" ) ); //$NON-NLS-1$ // Creating the layout of the section Composite objectClassesSectionClient = toolkit.createComposite( objectClassesSection ); objectClassesSectionClient.setLayout( new GridLayout() ); toolkit.paintBordersFor( objectClassesSectionClient ); objectClassesSection.setClient( objectClassesSectionClient ); objectClassesSection.setLayoutData( new GridData( SWT.FILL, SWT.FILL, true, true ) ); objectClassesTableViewer = new TableViewer( objectClassesSectionClient, SWT.SINGLE | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER ); objectClassesTableViewer.setContentProvider( new SchemaEditorTableViewerContentProvider() ); objectClassesTableViewer.setLabelProvider( new SchemaEditorTableViewerLabelProvider() ); objectClassesTableViewer.getTable().setLayoutData( new GridData( SWT.FILL, SWT.FILL, true, true ) ); } /** * Fills in the fields of the User Interface. */ private void fillInUiFields() { attributeTypesSection.setDescription( NLS.bind( Messages.getString( "SchemaEditorOverviewPage.SchemaAttribute" ), new String[] //$NON-NLS-1$ { originalSchema.getSchemaName() } ) ); objectClassesSection.setDescription( NLS.bind( Messages .getString( "SchemaEditorOverviewPage.SchemaObjectClasses" ), new String[] //$NON-NLS-1$ { originalSchema.getSchemaName() } ) ); attributeTypesTableViewer.setInput( originalSchema.getAttributeTypes() ); objectClassesTableViewer.setInput( originalSchema.getObjectClasses() ); } /** * Initializes and adds the listeners. */ private void addListeners() { attributeTypesTableViewer.addDoubleClickListener( attributeTypesTableViewerListener ); objectClassesTableViewer.addDoubleClickListener( objectClassesTableViewerListener ); } /** * Removes the listeners. */ private void removeListeners() { attributeTypesTableViewer.removeDoubleClickListener( attributeTypesTableViewerListener ); objectClassesTableViewer.removeDoubleClickListener( objectClassesTableViewerListener ); } /** * {@inheritDoc} */ public void dispose() { removeListeners(); Activator.getDefault().getSchemaHandler().removeListener( schemaHandlerListener ); super.dispose(); } /** * Refreshes the UI. */ public void refreshUI() { removeListeners(); fillInUiFields(); addListeners(); } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/dialogs/RenameObjectClassDialog.java
plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/dialogs/RenameObjectClassDialog.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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.apache.directory.studio.schemaeditor.view.dialogs; import java.util.List; import org.eclipse.swt.widgets.Shell; /** * This dialog is used to rename an object class. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class RenameObjectClassDialog extends EditObjectClassAliasesDialog { /** * Creates a new instance of RenameObjectClassDialog. * * @param aliases an array of aliases */ public RenameObjectClassDialog( List<String> aliases ) { super( aliases ); } /** * {@inheritDoc} */ protected void configureShell( Shell newShell ) { super.configureShell( newShell ); newShell.setText( Messages.getString( "RenameObjectClassDialog.RenameObjectClass" ) ); //$NON-NLS-1$ } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/dialogs/ObjectClassSelectionDialog.java
plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/dialogs/ObjectClassSelectionDialog.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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.apache.directory.studio.schemaeditor.view.dialogs; import java.util.ArrayList; import java.util.List; import org.apache.directory.api.ldap.model.schema.ObjectClass; import org.apache.directory.studio.schemaeditor.Activator; import org.apache.directory.studio.schemaeditor.PluginConstants; import org.eclipse.jface.dialogs.Dialog; import org.eclipse.jface.dialogs.IDialogConstants; import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.jface.viewers.DecoratingLabelProvider; import org.eclipse.jface.viewers.ISelectionChangedListener; import org.eclipse.jface.viewers.SelectionChangedEvent; import org.eclipse.jface.viewers.StructuredSelection; import org.eclipse.jface.viewers.TableViewer; import org.eclipse.swt.SWT; import org.eclipse.swt.events.KeyAdapter; import org.eclipse.swt.events.KeyEvent; import org.eclipse.swt.events.ModifyEvent; import org.eclipse.swt.events.ModifyListener; import org.eclipse.swt.events.MouseAdapter; import org.eclipse.swt.events.MouseEvent; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.widgets.Table; import org.eclipse.swt.widgets.Text; import org.eclipse.ui.PlatformUI; /** * This class is the Object Class Selection Dialog, that allows user to select an object class. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class ObjectClassSelectionDialog extends Dialog { /** The selected object class */ private ObjectClass selectedObjectClass; /** The hidden Object Classes */ private List<ObjectClass> hiddenObjectClasses; // UI Fields private Text searchText; private Table objectClassesTable; private TableViewer objectClassesTableViewer; private Label schemaIconLabel; private Label schemaNameLabel; private Button chooseButton; /** * Creates a new instance of ObjectClassSelectionDialog. */ public ObjectClassSelectionDialog() { super( PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell() ); hiddenObjectClasses = new ArrayList<ObjectClass>(); } /** * {@inheritDoc} */ protected void configureShell( Shell newShell ) { super.configureShell( newShell ); newShell.setText( Messages.getString( "ObjectClassSelectionDialog.ClassSelection" ) ); //$NON-NLS-1$ } /** * {@inheritDoc} */ protected Control createDialogArea( Composite parent ) { Composite composite = new Composite( parent, SWT.NONE ); GridLayout layout = new GridLayout( 1, false ); composite.setLayout( layout ); Label chooseLabel = new Label( composite, SWT.NONE ); chooseLabel.setText( Messages.getString( "ObjectClassSelectionDialog.ChooseClass" ) ); //$NON-NLS-1$ chooseLabel.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) ); searchText = new Text( composite, SWT.BORDER | SWT.SEARCH ); searchText.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) ); searchText.addModifyListener( new ModifyListener() { public void modifyText( ModifyEvent e ) { setSearchInput( searchText.getText() ); } } ); searchText.addKeyListener( new KeyAdapter() { public void keyPressed( KeyEvent e ) { if ( e.keyCode == SWT.ARROW_DOWN ) { objectClassesTable.setFocus(); } } } ); Label matchingLabel = new Label( composite, SWT.NONE ); matchingLabel.setText( Messages.getString( "ObjectClassSelectionDialog.MatchingClasses" ) ); //$NON-NLS-1$ matchingLabel.setLayoutData( new GridData( SWT.FILL, SWT.None, true, false ) ); objectClassesTable = new Table( composite, SWT.SINGLE | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.HIDE_SELECTION ); GridData gridData = new GridData( SWT.FILL, SWT.FILL, true, true ); gridData.heightHint = 148; gridData.minimumHeight = 148; gridData.widthHint = 350; gridData.minimumWidth = 350; objectClassesTable.setLayoutData( gridData ); objectClassesTable.addMouseListener( new MouseAdapter() { public void mouseDoubleClick( MouseEvent e ) { if ( objectClassesTable.getSelectionIndex() != -1 ) { okPressed(); } } } ); objectClassesTableViewer = new TableViewer( objectClassesTable ); objectClassesTableViewer .setContentProvider( new ObjectClassSelectionDialogContentProvider( hiddenObjectClasses ) ); objectClassesTableViewer.setLabelProvider( new DecoratingLabelProvider( new ObjectClassSelectionDialogLabelProvider(), Activator.getDefault().getWorkbench().getDecoratorManager() .getLabelDecorator() ) ); objectClassesTableViewer.addSelectionChangedListener( new ISelectionChangedListener() { public void selectionChanged( SelectionChangedEvent event ) { StructuredSelection selection = ( StructuredSelection ) objectClassesTableViewer.getSelection(); if ( selection.isEmpty() ) { if ( ( chooseButton != null ) && ( !chooseButton.isDisposed() ) ) { chooseButton.setEnabled( false ); } schemaIconLabel.setImage( Activator.getDefault().getImage( PluginConstants.IMG_TRANSPARENT_16X16 ) ); schemaNameLabel.setText( "" ); //$NON-NLS-1$ } else { if ( ( chooseButton != null ) && ( !chooseButton.isDisposed() ) ) { chooseButton.setEnabled( true ); } schemaIconLabel.setImage( Activator.getDefault().getImage( PluginConstants.IMG_SCHEMA ) ); schemaNameLabel.setText( ( ( ObjectClass ) selection.getFirstElement() ).getSchemaName() ); } } } ); // Schema Composite Composite schemaComposite = new Composite( composite, SWT.BORDER ); schemaComposite.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) ); GridLayout schemaCompositeGridLayout = new GridLayout( 2, false ); schemaCompositeGridLayout.horizontalSpacing = 0; schemaCompositeGridLayout.verticalSpacing = 0; schemaCompositeGridLayout.marginWidth = 2; schemaCompositeGridLayout.marginHeight = 2; schemaComposite.setLayout( schemaCompositeGridLayout ); // Schema Icon Label schemaIconLabel = new Label( schemaComposite, SWT.NONE ); GridData schemaIconLabelGridData = new GridData( SWT.NONE, SWT.BOTTOM, false, false ); schemaIconLabelGridData.widthHint = 18; schemaIconLabelGridData.heightHint = 16; schemaIconLabel.setLayoutData( schemaIconLabelGridData ); schemaIconLabel.setImage( Activator.getDefault().getImage( PluginConstants.IMG_TRANSPARENT_16X16 ) ); // Schema Name Label schemaNameLabel = new Label( schemaComposite, SWT.NONE ); schemaNameLabel.setLayoutData( new GridData( SWT.FILL, SWT.BOTTOM, true, false ) ); schemaNameLabel.setText( "" ); //$NON-NLS-1$ // We need to force the input to load the complete list of attribute types setSearchInput( "" ); //$NON-NLS-1$ return composite; } /** * {@inheritDoc} */ protected void createButtonsForButtonBar( Composite parent ) { chooseButton = createButton( parent, IDialogConstants.OK_ID, Messages .getString( "ObjectClassSelectionDialog.Choose" ), true ); //$NON-NLS-1$ createButton( parent, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL, false ); StructuredSelection selection = ( StructuredSelection ) objectClassesTableViewer.getSelection(); if ( selection.isEmpty() ) { if ( ( chooseButton != null ) && ( !chooseButton.isDisposed() ) ) { chooseButton.setEnabled( false ); } } else { if ( ( chooseButton != null ) && ( !chooseButton.isDisposed() ) ) { chooseButton.setEnabled( true ); } } } /** * {@inheritDoc} */ protected void okPressed() { StructuredSelection selection = ( StructuredSelection ) objectClassesTableViewer.getSelection(); if ( selection.isEmpty() ) { MessageDialog.openError( getShell(), Messages.getString( "ObjectClassSelectionDialog.InvalidSelection" ), //$NON-NLS-1$ Messages.getString( "ObjectClassSelectionDialog.MustChooseClass" ) ); //$NON-NLS-1$ return; } else { selectedObjectClass = ( ObjectClass ) selection.getFirstElement(); } super.okPressed(); } /** * Returns the selected Object Class. * * @return * the selected Object Class */ public ObjectClass getSelectedObjectClass() { return selectedObjectClass; } /** * Set the hidden Object Classes. * * @param list * a list of Object Classes to hide */ public void setHiddenObjectClasses( List<ObjectClass> list ) { hiddenObjectClasses = list; } /** * Sets the hidden Object Classes. * * @param objectClasses * an array of Object Classes to hide */ public void setHiddenObjectClasses( ObjectClass[] objectClasses ) { for ( ObjectClass objectClass : objectClasses ) { hiddenObjectClasses.add( objectClass ); } } /** * Set the Search Input. * * @param searchString * the Search String */ private void setSearchInput( String searchString ) { objectClassesTableViewer.setInput( searchString ); Object firstElement = objectClassesTableViewer.getElementAt( 0 ); if ( firstElement != null ) { objectClassesTableViewer.setSelection( new StructuredSelection( firstElement ), true ); } } /** * {@inheritDoc} */ public boolean close() { hiddenObjectClasses.clear(); hiddenObjectClasses = null; objectClassesTableViewer = null; objectClassesTable.dispose(); objectClassesTable = null; searchText.dispose(); searchText = null; schemaIconLabel.dispose(); schemaIconLabel = null; schemaNameLabel.dispose(); schemaNameLabel = null; return super.close(); } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/dialogs/AbstractAliasesDialog.java
plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/dialogs/AbstractAliasesDialog.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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.apache.directory.studio.schemaeditor.view.dialogs; import java.util.ArrayList; import java.util.List; import org.apache.directory.api.util.Strings; import org.apache.directory.studio.schemaeditor.Activator; import org.apache.directory.studio.schemaeditor.PluginUtils; import org.eclipse.jface.action.Action; import org.eclipse.jface.dialogs.Dialog; import org.eclipse.osgi.util.NLS; import org.eclipse.swt.SWT; import org.eclipse.swt.custom.TableEditor; import org.eclipse.swt.events.KeyAdapter; import org.eclipse.swt.events.KeyEvent; import org.eclipse.swt.events.ModifyEvent; import org.eclipse.swt.events.ModifyListener; import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.graphics.Image; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Event; import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Listener; import org.eclipse.swt.widgets.Menu; import org.eclipse.swt.widgets.MenuItem; import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.widgets.Table; import org.eclipse.swt.widgets.TableItem; import org.eclipse.swt.widgets.Text; import org.eclipse.ui.ISharedImages; import org.eclipse.ui.PlatformUI; /** * This class implements dialog to manage aliases. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public abstract class AbstractAliasesDialog extends Dialog { /** The aliases List */ private List<String> initialLowerCasedAliases = new ArrayList<String>(); private List<String> aliases = new ArrayList<String>(); private List<String> lowerCasedAliases = new ArrayList<String>(); /** The listener used to override the listerner on the RETURN key */ private Listener returnKeyListener = new Listener() { public void handleEvent( Event event ) { if ( event.detail == SWT.TRAVERSE_RETURN ) { event.detail = SWT.TRAVERSE_TAB_NEXT; closeTableEditor(); } } }; // UI Fields private Table aliasesTable; private TableEditor tableEditor; private Button addButton; private Button editButton; private Button removeButton; private Composite errorComposite; private Image errorImage; private Label errorLabel; /** * Creates a new instance of AbstractAliasesDialog. * * @param aliases an array of aliases */ public AbstractAliasesDialog( List<String> aliases ) { super( PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell() ); if ( aliases != null ) { for ( String alias : aliases ) { initialLowerCasedAliases.add( Strings.toLowerCase( alias ) ); this.aliases.add( alias ); lowerCasedAliases.add( Strings.toLowerCase( alias ) ); } } } /** * {@inheritDoc} */ protected Control createDialogArea( Composite parent ) { // Creating the composite Composite composite = new Composite( parent, SWT.NONE ); composite.setLayout( new GridLayout( 2, false ) ); composite.setLayoutData( new GridData( SWT.FILL, SWT.FILL, true, true ) ); // Aliases Label Label aliasesLabel = new Label( composite, SWT.NONE ); aliasesLabel.setText( Messages.getString( "AbstractAliasesDialog.Aliases" ) ); //$NON-NLS-1$ aliasesLabel.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, true, 2, 1 ) ); // Aliases Table aliasesTable = new Table( composite, SWT.BORDER | SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.HIDE_SELECTION ); GridData gridData = new GridData( SWT.FILL, SWT.FILL, true, true, 1, 3 ); gridData.heightHint = 90; gridData.minimumHeight = 90; gridData.widthHint = 200; gridData.minimumWidth = 200; aliasesTable.setLayoutData( gridData ); // Aliases Table Editor tableEditor = new TableEditor( aliasesTable ); tableEditor.horizontalAlignment = SWT.LEFT; tableEditor.grabHorizontal = true; tableEditor.minimumWidth = 200; // Add Button addButton = new Button( composite, SWT.PUSH ); addButton.setText( Messages.getString( "AbstractAliasesDialog.Add" ) ); //$NON-NLS-1$ addButton.setLayoutData( new GridData( SWT.FILL, SWT.NONE, false, false ) ); // Edit Button editButton = new Button( composite, SWT.PUSH ); editButton.setText( Messages.getString( "AbstractAliasesDialog.Edit" ) ); //$NON-NLS-1$ editButton.setLayoutData( new GridData( SWT.FILL, SWT.NONE, false, false ) ); editButton.setEnabled( false ); // Remove Button removeButton = new Button( composite, SWT.PUSH ); removeButton.setText( Messages.getString( "AbstractAliasesDialog.Remove" ) ); //$NON-NLS-1$ removeButton.setLayoutData( new GridData( SWT.FILL, SWT.NONE, false, false ) ); removeButton.setEnabled( false ); // Error Composite errorComposite = new Composite( composite, SWT.NONE ); errorComposite.setLayout( new GridLayout( 2, false ) ); errorComposite.setLayoutData( new GridData( SWT.FILL, SWT.FILL, true, true, 2, 1 ) ); errorComposite.setVisible( false ); // Error Image errorImage = PlatformUI.getWorkbench().getSharedImages().getImage( ISharedImages.IMG_OBJS_ERROR_TSK ); Label label = new Label( errorComposite, SWT.NONE ); label.setImage( errorImage ); label.setSize( 16, 16 ); // Error Label errorLabel = new Label( errorComposite, SWT.NONE ); errorLabel.setLayoutData( new GridData( SWT.FILL, SWT.FILL, true, true ) ); errorLabel.setText( getAliasAlreadyExistsErrorMessage() ); // Filling the Table with the given aliases fillAliasesTable(); // Listeners initialization initListeners(); // Checking the aliases checkAliases(); return composite; } /** * Fills in the Aliases Table from the aliases list */ private void fillAliasesTable() { aliasesTable.removeAll(); aliasesTable.setItemCount( 0 ); for ( String alias : aliases ) { TableItem newItem = new TableItem( aliasesTable, SWT.NONE ); newItem.setText( alias ); } } /** * Initializes the Listeners. */ private void initListeners() { aliasesTable.addKeyListener( new KeyAdapter() { public void keyPressed( KeyEvent e ) { if ( ( e.keyCode == SWT.DEL ) || ( e.keyCode == Action.findKeyCode( "BACKSPACE" ) ) ) //$NON-NLS-1$ { removeSelectedAliases(); fillAliasesTable(); updateButtonsState(); checkAliases(); } } } ); aliasesTable.addSelectionListener( new SelectionAdapter() { public void widgetSelected( SelectionEvent e ) { closeTableEditor(); updateButtonsState(); } } ); aliasesTable.addListener( SWT.MouseDoubleClick, new Listener() { public void handleEvent( Event event ) { openTableEditor( aliasesTable.getItem( aliasesTable.getSelectionIndex() ) ); } } ); // Aliases Table's Popup Menu Menu menu = new Menu( getShell(), SWT.POP_UP ); aliasesTable.setMenu( menu ); MenuItem removeMenuItem = new MenuItem( menu, SWT.PUSH ); removeMenuItem.setText( Messages.getString( "AbstractAliasesDialog.Remove" ) ); //$NON-NLS-1$ removeMenuItem.setImage( PlatformUI.getWorkbench().getSharedImages().getImage( ISharedImages.IMG_TOOL_DELETE ) ); removeMenuItem.addListener( SWT.Selection, new Listener() { public void handleEvent( Event event ) { removeSelectedAliases(); fillAliasesTable(); updateButtonsState(); checkAliases(); } } ); // Add Button addButton.addSelectionListener( new SelectionAdapter() { public void widgetSelected( SelectionEvent e ) { addANewAlias(); } } ); // Edit Button editButton.addSelectionListener( new SelectionAdapter() { public void widgetSelected( SelectionEvent e ) { openTableEditor( aliasesTable.getItem( aliasesTable.getSelectionIndex() ) ); } } ); // Remove Button removeButton.addSelectionListener( new SelectionAdapter() { public void widgetSelected( SelectionEvent e ) { removeSelectedAliases(); fillAliasesTable(); updateButtonsState(); checkAliases(); } } ); } /** * Updates the state of the buttons. */ private void updateButtonsState() { if ( aliasesTable.getSelectionCount() >= 1 ) { editButton.setEnabled( true ); removeButton.setEnabled( true ); } else { editButton.setEnabled( false ); removeButton.setEnabled( false ); } } /** * Removes the selected aliases. */ private void removeSelectedAliases() { TableItem[] selectedItems = aliasesTable.getSelection(); for ( TableItem item : selectedItems ) { aliases.remove( item.getText() ); lowerCasedAliases.remove( Strings.toLowerCase( item.getText() ) ); } } /** * Adds a new alias */ private void addANewAlias() { TableItem item = new TableItem( aliasesTable, SWT.NONE ); item.setText( "" ); //$NON-NLS-1$ openTableEditor( item ); } /** * Opens the {@link TableEditor} on the given {@link TableItem}. * * @param item * the {@link TableItem} */ private void openTableEditor( TableItem item ) { // Clean up any previous editor control Control oldEditor = tableEditor.getEditor(); if ( oldEditor != null ) oldEditor.dispose(); if ( item == null ) return; // The control that will be the editor must be a child of the Table Text newEditor = new Text( aliasesTable, SWT.NONE ); newEditor.setText( item.getText() ); newEditor.addModifyListener( new ModifyListener() { public void modifyText( ModifyEvent e ) { saveTableEditorText(); } } ); newEditor.addKeyListener( new KeyAdapter() { public void keyPressed( KeyEvent e ) { if ( ( e.keyCode == Action.findKeyCode( "RETURN" ) ) || ( e.keyCode == SWT.KEYPAD_CR ) ) //$NON-NLS-1$ { closeTableEditor(); } } } ); newEditor.selectAll(); newEditor.setFocus(); tableEditor.setEditor( newEditor, item, 0 ); Activator.getDefault().getWorkbench().getDisplay().addFilter( SWT.Traverse, returnKeyListener ); } /** * Saves the {@link TableEditor} text. */ private void saveTableEditorText() { Text text = ( Text ) tableEditor.getEditor(); if ( ( text != null ) && ( !text.isDisposed() ) ) { TableItem item = tableEditor.getItem(); String oldText = item.getText(); String newText = text.getText(); if ( !oldText.equals( newText ) ) { aliases.remove( oldText ); lowerCasedAliases.remove( Strings.toLowerCase( oldText ) ); if ( !newText.equals( "" ) ) //$NON-NLS-1$ { aliases.add( newText ); lowerCasedAliases.add( Strings.toLowerCase( newText ) ); } item.setText( newText ); } } checkAliases(); } /** * Closes the {@link TableEditor}. */ private void closeTableEditor() { Text text = ( Text ) tableEditor.getEditor(); if ( ( text != null ) && ( !text.isDisposed() ) ) { saveTableEditorText(); text.dispose(); } Activator.getDefault().getWorkbench().getDisplay().removeFilter( SWT.Traverse, returnKeyListener ); } /** * Checks the aliases. */ private void checkAliases() { errorComposite.setVisible( false ); for ( String alias : aliases ) { if ( ( isAliasAlreadyTaken( alias ) ) && ( !initialLowerCasedAliases.contains( Strings.toLowerCase( alias ) ) ) ) { errorComposite.setVisible( true ); errorLabel.setText( getAliasAlreadyExistsErrorMessage() ); return; } else if ( !PluginUtils.verifyName( alias ) ) { errorComposite.setVisible( true ); errorLabel.setText( NLS.bind( Messages.getString( "AbstractAliasesDialog.InvalidAlias" ), new String[] //$NON-NLS-1$ { alias } ) ); return; } } } /** * {@inheritDoc} */ protected void configureShell( Shell newShell ) { super.configureShell( newShell ); newShell.setText( Messages.getString( "AbstractAliasesDialog.EditAlias" ) ); //$NON-NLS-1$ } /** * Returns the aliases. * * @return * the aliases */ public String[] getAliases() { return aliases.toArray( new String[0] ); } /** * Gets the error message in the case where an identical alias already exists. * * @return the error message */ protected abstract String getAliasAlreadyExistsErrorMessage(); /** * Checks if the given alias is already taken. * * @return <code>true</code> if the given alias is already taken, * <code>false</code> if not. */ protected abstract boolean isAliasAlreadyTaken( String alias ); }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/dialogs/RenameAttributeTypeDialog.java
plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/dialogs/RenameAttributeTypeDialog.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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.apache.directory.studio.schemaeditor.view.dialogs; import java.util.List; import org.eclipse.swt.widgets.Shell; /** * This dialog is used to rename an attribute type. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class RenameAttributeTypeDialog extends EditAttributeTypeAliasesDialog { /** * Creates a new instance of RenameAttributeTypeDialog. * * @param aliases an array of aliases */ public RenameAttributeTypeDialog( List<String> aliases ) { super( aliases ); } /** * {@inheritDoc} */ protected void configureShell( Shell newShell ) { super.configureShell( newShell ); newShell.setText( Messages.getString( "RenameAttributeTypeDialog.RenameAttributeType" ) ); //$NON-NLS-1$ } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false