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/view/dialogs/AbstractRenameDialog.java
plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/dialogs/AbstractRenameDialog.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 org.eclipse.jface.dialogs.Dialog; import org.eclipse.jface.dialogs.IDialogConstants; import org.eclipse.swt.SWT; import org.eclipse.swt.events.ModifyEvent; import org.eclipse.swt.events.ModifyListener; 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.Label; import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.widgets.Text; import org.eclipse.ui.ISharedImages; import org.eclipse.ui.PlatformUI; /** * This dialog is used to rename items like projects or schemas. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public abstract class AbstractRenameDialog extends Dialog { /** The original name*/ private String originalName; /** The new name */ private String newName; // UI Fields private Text newNameText; private Composite errorComposite; private Image errorImage; private Label errorLabel; private Button okButton; /** * Creates a new instance of AbstractRenameDialog. * * @param originalName * the original name */ public AbstractRenameDialog( String originalName ) { super( PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell() ); this.originalName = originalName; this.newName = originalName; } /** * {@inheritDoc} */ protected void configureShell( Shell newShell ) { super.configureShell( newShell ); newShell.setText( Messages.getString( "RenameProjectDialog.Rename" ) ); //$NON-NLS-1$ } /** * {@inheritDoc} */ protected Control createDialogArea( Composite parent ) { Composite composite = new Composite( parent, SWT.NONE ); composite.setLayout( new GridLayout( 2, false ) ); composite.setLayoutData( new GridData( SWT.FILL, SWT.FILL, true, true ) ); // New Name Label newNameLabel = new Label( composite, SWT.NONE ); newNameLabel.setText( Messages.getString( "AbstractRenameDialog.NewName" ) ); //$NON-NLS-1$ newNameText = new Text( composite, SWT.BORDER ); newNameText.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) ); newNameText.setText( originalName ); newNameText.addModifyListener( new ModifyListener() { public void modifyText( ModifyEvent e ) { // Getting the new name newName = newNameText.getText(); if ( !newName.equalsIgnoreCase( originalName ) ) { // Checking if the new is already taken boolean checkNewName = isNewNameAlreadyTaken(); // Enabling (or not) the ok button and showing (or not) the error composite okButton.setEnabled( !checkNewName ); errorComposite.setVisible( checkNewName ); } else { // Enabling the ok button and showing the error composite okButton.setEnabled( true ); errorComposite.setVisible( 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( getErrorMessage() ); newNameText.setFocus(); newNameText.selectAll(); return composite; } /** * {@inheritDoc} */ protected void createButtonsForButtonBar( Composite parent ) { createButton( parent, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL, false ); okButton = createButton( parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, true ); } /** * Returns the new name. * * @return * the new name */ public String getNewName() { return newName; } /** * Gets the error message. * * @return the error message */ protected abstract String getErrorMessage(); /** * Checks if the new name is already taken. * * @return <code>true</code> if the new name is already taken, * <code>false</code> if not. */ protected abstract boolean isNewNameAlreadyTaken(); }
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/PreviousSearchesDialog.java
plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/dialogs/PreviousSearchesDialog.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 org.apache.directory.studio.schemaeditor.Activator; import org.apache.directory.studio.schemaeditor.PluginConstants; import org.apache.directory.studio.schemaeditor.view.search.SearchPage; import org.apache.directory.studio.schemaeditor.view.search.SearchPage.SearchInEnum; import org.apache.directory.studio.schemaeditor.view.views.SearchView; import org.eclipse.jface.dialogs.Dialog; import org.eclipse.jface.dialogs.IDialogConstants; import org.eclipse.jface.viewers.ArrayContentProvider; import org.eclipse.jface.viewers.DoubleClickEvent; import org.eclipse.jface.viewers.IDoubleClickListener; import org.eclipse.jface.viewers.ISelectionChangedListener; import org.eclipse.jface.viewers.LabelProvider; 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.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.Label; import org.eclipse.swt.widgets.Shell; import org.eclipse.ui.PlatformUI; /** * This dialog is used to display the previous searches. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class PreviousSearchesDialog extends Dialog { /** The associated view */ private SearchView view; // UI Fields private TableViewer tableViewer; private Button openButton; private Button removeButton; /** * Creates a new instance of PreviousSearchesDialog. */ public PreviousSearchesDialog( SearchView view ) { super( PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell() ); this.view = view; } /** * {@inheritDoc} */ protected void configureShell( Shell newShell ) { super.configureShell( newShell ); newShell.setText( Messages.getString( "PreviousSearchesDialog.Previous" ) ); //$NON-NLS-1$ } /** * {@inheritDoc} */ protected Control createDialogArea( Composite parent ) { Composite composite = new Composite( parent, SWT.NONE ); composite.setLayout( new GridLayout( 2, false ) ); composite.setLayoutData( new GridData( SWT.FILL, SWT.FILL, true, true ) ); Label label = new Label( composite, SWT.NONE ); label.setText( Messages.getString( "PreviousSearchesDialog.ShowResultsInView" ) ); //$NON-NLS-1$ label.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false, 2, 1 ) ); tableViewer = new TableViewer( composite, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL | SWT.SINGLE ); GridData gd = new GridData( SWT.FILL, SWT.NONE, true, false ); gd.widthHint = 300; gd.heightHint = 200; tableViewer.getTable().setLayoutData( gd ); tableViewer.setContentProvider( new ArrayContentProvider() ); tableViewer.setLabelProvider( new LabelProvider() { public Image getImage( Object element ) { return Activator.getDefault().getImage( PluginConstants.IMG_SEARCH_HISTORY_ITEM ); } } ); tableViewer.addSelectionChangedListener( new ISelectionChangedListener() { public void selectionChanged( SelectionChangedEvent event ) { openButton.setEnabled( !event.getSelection().isEmpty() ); removeButton.setEnabled( !event.getSelection().isEmpty() ); } } ); tableViewer.addDoubleClickListener( new IDoubleClickListener() { public void doubleClick( DoubleClickEvent event ) { buttonPressed( IDialogConstants.OK_ID ); } } ); removeButton = new Button( composite, SWT.NONE ); removeButton.setText( Messages.getString( "PreviousSearchesDialog.Remove" ) ); //$NON-NLS-1$ removeButton.setLayoutData( new GridData( SWT.NONE, SWT.BEGINNING, false, false ) ); removeButton.setEnabled( false ); removeButton.addSelectionListener( new SelectionAdapter() { public void widgetSelected( SelectionEvent e ) { StructuredSelection selection = ( StructuredSelection ) tableViewer.getSelection(); String selectedSearch = ( String ) selection.getFirstElement(); SearchPage.removeSearchStringHistory( selectedSearch ); initTableViewer(); } } ); initTableViewer(); return composite; } /** * Initializes the TableViewer. */ private void initTableViewer() { tableViewer.setInput( SearchPage.loadSearchStringHistory() ); } /** * {@inheritDoc} */ protected void createButtonsForButtonBar( Composite parent ) { createButton( parent, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL, false ); openButton = createButton( parent, IDialogConstants.OK_ID, Messages.getString( "PreviousSearchesDialog.Open" ), //$NON-NLS-1$ true ); openButton.setEnabled( false ); } /** * {@inheritDoc} */ protected void buttonPressed( int buttonId ) { if ( buttonId == IDialogConstants.OK_ID ) { if ( !tableViewer.getSelection().isEmpty() ) { StructuredSelection selection = ( StructuredSelection ) tableViewer.getSelection(); String selectedSearch = ( String ) selection.getFirstElement(); view.setSearchInput( selectedSearch, SearchPage.loadSearchIn().toArray( new SearchInEnum[0] ), SearchPage.loadScope() ); } } 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/dialogs/EditAttributeTypeAliasesDialog.java
plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/dialogs/EditAttributeTypeAliasesDialog.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.apache.directory.studio.schemaeditor.Activator; import org.eclipse.swt.widgets.Shell; /** * This dialog is used to edit aliases of an attribute type. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class EditAttributeTypeAliasesDialog extends AbstractAliasesDialog { /** * Creates a new instance of EditAttributeTypeAliasesDialog. * * @param aliases an array of aliases */ public EditAttributeTypeAliasesDialog( List<String> aliases ) { super( aliases ); } /** * {@inheritDoc} */ protected void configureShell( Shell newShell ) { super.configureShell( newShell ); newShell.setText( Messages.getString( "EditAttributeTypeAliasesDialog.EditAliases" ) ); //$NON-NLS-1$ } /** * {@inheritDoc} */ protected String getAliasAlreadyExistsErrorMessage() { return Messages.getString( "EditAttributeTypeAliasesDialog.AliasAlreadyExists" ); //$NON-NLS-1$ } /** * {@inheritDoc} */ protected boolean isAliasAlreadyTaken( String alias ) { return Activator.getDefault().getSchemaHandler().isAliasAlreadyTakenForAttributeType( 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/ObjectClassSelectionDialogContentProvider.java
plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/dialogs/ObjectClassSelectionDialogContentProvider.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.Collections; import java.util.Comparator; import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern; 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.eclipse.jface.viewers.IStructuredContentProvider; import org.eclipse.jface.viewers.Viewer; /** * This class is the Content Provider for the Object Class Selection Dialog. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class ObjectClassSelectionDialogContentProvider implements IStructuredContentProvider { /** The schema handler */ private SchemaHandler schemaHandler; /** The hidden object classes */ private List<ObjectClass> hiddenObjectClasses; /** * Creates a new instance of ObjectClassSelectionDialogContentProvider. */ public ObjectClassSelectionDialogContentProvider( List<ObjectClass> hiddenObjectClasses ) { schemaHandler = Activator.getDefault().getSchemaHandler(); this.hiddenObjectClasses = hiddenObjectClasses; } /** * {@inheritDoc} */ public Object[] getElements( Object inputElement ) { if ( inputElement instanceof String ) { ArrayList<ObjectClass> results = new ArrayList<ObjectClass>(); String searchText = ( String ) inputElement; String searchRegexp; searchText += "*"; //$NON-NLS-1$ searchRegexp = searchText.replaceAll( "\\*", "[\\\\S]*" ); //$NON-NLS-1$ //$NON-NLS-2$ searchRegexp = searchRegexp.replaceAll( "\\?", "[\\\\S]" ); //$NON-NLS-1$ //$NON-NLS-2$ Pattern pattern = Pattern.compile( searchRegexp, Pattern.CASE_INSENSITIVE ); List<ObjectClass> ocList = schemaHandler.getObjectClasses(); // Sorting the list Collections.sort( ocList, new Comparator<ObjectClass>() { public int compare( ObjectClass oc1, ObjectClass oc2 ) { List<String> oc1Names = ( ( ObjectClass ) oc1 ).getNames(); List<String> oc2Names = ( ( ObjectClass ) oc2 ).getNames(); if ( ( oc1Names == null || oc1Names.size() == 0 ) && ( oc2Names == null || oc2Names.size() == 0 ) ) { return 0; } else if ( ( oc1Names == null || oc1Names.size() == 0 ) && ( oc2Names != null && oc2Names.size() > 0 ) ) { return "".compareToIgnoreCase( oc2Names.get( 0 ) ); //$NON-NLS-1$ } else if ( ( oc1Names != null && oc1Names.size() > 0 ) && ( oc2Names == null || oc2Names.size() == 0 ) ) { return oc1Names.get( 0 ).compareToIgnoreCase( "" ); //$NON-NLS-1$ } else { return oc1Names.get( 0 ).compareToIgnoreCase( oc2Names.get( 0 ) ); } } } ); // Searching for all matching elements for ( ObjectClass oc : ocList ) { for ( String name : oc.getNames() ) { Matcher m = pattern.matcher( name ); if ( m.matches() ) { if ( !hiddenObjectClasses.contains( oc ) ) { if ( !results.contains( oc ) ) { results.add( oc ); } } break; } } Matcher m = pattern.matcher( oc.getOid() ); if ( m.matches() ) { if ( !hiddenObjectClasses.contains( oc ) ) { if ( !results.contains( oc ) ) { results.add( oc ); } } } } // Returns the results return results.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/dialogs/Messages.java
plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/dialogs/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.dialogs; 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/dialogs/AttributeTypeSelectionDialog.java
plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/dialogs/AttributeTypeSelectionDialog.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.AttributeType; 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 Attribute Type Selection Dialog, that allows user to select an attribute type. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class AttributeTypeSelectionDialog extends Dialog { /** The selected attribute type */ private AttributeType selectedAttributeType; /** The hidden attribute types */ private List<AttributeType> hiddenAttributeTypes; // UI Fields private Text searchText; private Table attributeTypesTable; private TableViewer attributeTypesTableViewer; private Label schemaIconLabel; private Label schemaNameLabel; private Button chooseButton; /** * Creates a new instance of AttributeTypeSelectionDialog. */ public AttributeTypeSelectionDialog() { super( PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell() ); hiddenAttributeTypes = new ArrayList<AttributeType>(); } /** * {@inheritDoc} */ protected void configureShell( Shell newShell ) { super.configureShell( newShell ); newShell.setText( Messages.getString( "AttributeTypeSelectionDialog.TypeSelection" ) ); //$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( "AttributeTypeSelectionDialog.ChooseAType" ) ); //$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 ) { attributeTypesTable.setFocus(); } } } ); Label matchingLabel = new Label( composite, SWT.NONE ); matchingLabel.setText( Messages.getString( "AttributeTypeSelectionDialog.MatchingTypes" ) ); //$NON-NLS-1$ matchingLabel.setLayoutData( new GridData( SWT.FILL, SWT.None, true, false ) ); attributeTypesTable = 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; attributeTypesTable.setLayoutData( gridData ); attributeTypesTable.addMouseListener( new MouseAdapter() { public void mouseDoubleClick( MouseEvent e ) { if ( attributeTypesTable.getSelectionIndex() != -1 ) { okPressed(); } } } ); attributeTypesTableViewer = new TableViewer( attributeTypesTable ); attributeTypesTableViewer.setContentProvider( new AttributeTypeSelectionDialogContentProvider( hiddenAttributeTypes ) ); attributeTypesTableViewer.setLabelProvider( new DecoratingLabelProvider( new AttributeTypeSelectionDialogLabelProvider(), Activator.getDefault().getWorkbench() .getDecoratorManager().getLabelDecorator() ) ); attributeTypesTableViewer.addSelectionChangedListener( new ISelectionChangedListener() { public void selectionChanged( SelectionChangedEvent event ) { StructuredSelection selection = ( StructuredSelection ) attributeTypesTableViewer.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( ( ( AttributeType ) 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( "AttributeTypeSelectionDialog.Choose" ), true ); //$NON-NLS-1$ createButton( parent, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL, false ); StructuredSelection selection = ( StructuredSelection ) attributeTypesTableViewer.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 ) attributeTypesTableViewer.getSelection(); if ( selection.isEmpty() ) { MessageDialog.openError( getShell(), Messages.getString( "AttributeTypeSelectionDialog.InvalidSelection" ), //$NON-NLS-1$ Messages.getString( "AttributeTypeSelectionDialog.MustChooseType" ) ); //$NON-NLS-1$ return; } else { selectedAttributeType = ( AttributeType ) selection.getFirstElement(); } super.okPressed(); } /** * Returns the selected Attribute Type. * * @return * the selected Attribute Type */ public AttributeType getSelectedAttributeType() { return selectedAttributeType; } /** * Set the hidden Attribute Types. * * @param list * a list of Attribute Types to hide */ public void setHiddenAttributeTypes( List<AttributeType> list ) { hiddenAttributeTypes = list; } /** * Sets the hidden Attribute Types. * * @param attributeTypes * an array of Attribute Types to hide */ public void setHiddenAttributeTypes( AttributeType[] attributeTypes ) { for ( AttributeType objectClass : attributeTypes ) { hiddenAttributeTypes.add( objectClass ); } } /** * Set the Search Input. * * @param searchString * the Search String */ private void setSearchInput( String searchString ) { attributeTypesTableViewer.setInput( searchString ); Object firstElement = attributeTypesTableViewer.getElementAt( 0 ); if ( firstElement != null ) { attributeTypesTableViewer.setSelection( new StructuredSelection( firstElement ), true ); } } /** * {@inheritDoc} */ public boolean close() { hiddenAttributeTypes.clear(); hiddenAttributeTypes = null; attributeTypesTableViewer = null; attributeTypesTable.dispose(); attributeTypesTable = 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/EditObjectClassAliasesDialog.java
plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/dialogs/EditObjectClassAliasesDialog.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.apache.directory.studio.schemaeditor.Activator; import org.eclipse.swt.widgets.Shell; /** * This dialog is used to edit aliases of an object class. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class EditObjectClassAliasesDialog extends AbstractAliasesDialog { /** * Creates a new instance of EditObjectClassAliasesDialog. * * @param aliases an array of aliases */ public EditObjectClassAliasesDialog( List<String> aliases ) { super( aliases ); } /** * {@inheritDoc} */ protected void configureShell( Shell newShell ) { super.configureShell( newShell ); newShell.setText( Messages.getString( "EditObjectClassAliasesDialog.EditAliases" ) ); //$NON-NLS-1$ } /** * {@inheritDoc} */ protected String getAliasAlreadyExistsErrorMessage() { return Messages.getString( "EditObjectClassAliasesDialog.AliasAlreadyExists" ); //$NON-NLS-1$ } /** * {@inheritDoc} */ protected boolean isAliasAlreadyTaken( String alias ) { return Activator.getDefault().getSchemaHandler().isAliasAlreadyTakenForObjectClass( 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/AttributeTypeSelectionDialogContentProvider.java
plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/dialogs/AttributeTypeSelectionDialogContentProvider.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.Collections; import java.util.Comparator; import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern; 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.eclipse.jface.viewers.IStructuredContentProvider; import org.eclipse.jface.viewers.Viewer; /** * This class is the Content Provider for the Attribute Type Selection Dialog. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class AttributeTypeSelectionDialogContentProvider implements IStructuredContentProvider { /** The Schema Pool */ private SchemaHandler schemaHandler; /** The hidden Object Classes */ private List<AttributeType> hiddenAttributeTypes; /** * Creates a new instance of AttributeTypeSelectionDialogContentProvider. */ public AttributeTypeSelectionDialogContentProvider( List<AttributeType> hiddenAttributeTypes ) { this.hiddenAttributeTypes = hiddenAttributeTypes; schemaHandler = Activator.getDefault().getSchemaHandler(); } /** * {@inheritDoc} */ public Object[] getElements( Object inputElement ) { if ( inputElement instanceof String ) { ArrayList<AttributeType> results = new ArrayList<AttributeType>(); String searchText = ( String ) inputElement; String searchRegexp; searchText += "*"; //$NON-NLS-1$ searchRegexp = searchText.replaceAll( "\\*", "[\\\\S]*" ); //$NON-NLS-1$ //$NON-NLS-2$ searchRegexp = searchRegexp.replaceAll( "\\?", "[\\\\S]" ); //$NON-NLS-1$ //$NON-NLS-2$ Pattern pattern = Pattern.compile( searchRegexp, Pattern.CASE_INSENSITIVE ); List<AttributeType> atList = schemaHandler.getAttributeTypes(); // Sorting the list Collections.sort( atList, new Comparator<AttributeType>() { public int compare( AttributeType at1, AttributeType at2 ) { List<String> at1Names = ( ( AttributeType ) at1 ).getNames(); List<String> at2Names = ( ( AttributeType ) at2 ).getNames(); if ( ( at1Names == null || at1Names.size() == 0 ) && ( at2Names == null || at2Names.size() == 0 ) ) { return 0; } else if ( ( at1Names == null || at1Names.size() == 0 ) && ( at2Names != null && at2Names.size() > 0 ) ) { return "".compareToIgnoreCase( at2Names.get( 0 ) ); //$NON-NLS-1$ } else if ( ( at1Names != null && at1Names.size() > 0 ) && ( at2Names == null || at2Names.size() == 0 ) ) { return at1Names.get( 0 ).compareToIgnoreCase( "" ); //$NON-NLS-1$ } else { return at1Names.get( 0 ).compareToIgnoreCase( at2Names.get( 0 ) ); } } } ); // Searching for all matching elements for ( AttributeType at : atList ) { for ( String name : at.getNames() ) { Matcher m = pattern.matcher( name ); if ( m.matches() ) { if ( !hiddenAttributeTypes.contains( at ) ) { if ( !results.contains( at ) ) { results.add( at ); } } break; } } Matcher m = pattern.matcher( at.getOid() ); if ( m.matches() ) { if ( !hiddenAttributeTypes.contains( at ) ) { if ( !results.contains( at ) ) { results.add( at ); } } } } // Returns the results return results.toArray(); } // Default return new Object[0]; } /** * {@inheritDoc} */ public void dispose() { // Nothing to do } /** * {@inheritDoc} */ public void inputChanged( Viewer viewer, Object oldInput, Object newInput ) { // Nothing to do } }
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/RenameSchemaDialog.java
plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/dialogs/RenameSchemaDialog.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 org.apache.directory.studio.schemaeditor.Activator; import org.eclipse.swt.widgets.Shell; /** * this dialog is used to rename a project. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class RenameSchemaDialog extends AbstractRenameDialog { /** * Creates a new instance of RenameSchemaDialog. * * @param originalName * the original name of the project */ public RenameSchemaDialog( String originalName ) { super( originalName ); } /** * {@inheritDoc} */ protected void configureShell( Shell newShell ) { super.configureShell( newShell ); newShell.setText( Messages.getString( "RenameSchemaDialog.Rename" ) ); //$NON-NLS-1$ } /** * {@inheritDoc} */ protected String getErrorMessage() { return Messages.getString( "RenameSchemaDialog.NameExists" ); //$NON-NLS-1$ } /** * {@inheritDoc} */ protected boolean isNewNameAlreadyTaken() { return Activator.getDefault().getSchemaHandler().isSchemaNameAlreadyTaken( getNewName() ); } }
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/AttributeTypeSelectionDialogLabelProvider.java
plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/dialogs/AttributeTypeSelectionDialogLabelProvider.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.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.eclipse.jface.viewers.LabelProvider; import org.eclipse.osgi.util.NLS; import org.eclipse.swt.graphics.Image; /** * This class is the Label Provider for the Attribute Types Viewer of the AttributeTypeSelectionDialog. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class AttributeTypeSelectionDialogLabelProvider extends LabelProvider { /** * {@inheritDoc} */ public Image getImage( Object element ) { if ( element instanceof AttributeType ) { return Activator.getDefault().getImage( PluginConstants.IMG_ATTRIBUTE_TYPE ); } // Default return null; } /** * {@inheritDoc} */ public String getText( Object element ) { 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( "AttributeTypeSelectionDialogLabelProvider.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/dialogs/ObjectClassSelectionDialogLabelProvider.java
plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/dialogs/ObjectClassSelectionDialogLabelProvider.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.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.LabelProvider; import org.eclipse.osgi.util.NLS; import org.eclipse.swt.graphics.Image; /** * This class is the Label Provider for the Object Classes Viewer of the ObjectClassSelectionDialog. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class ObjectClassSelectionDialogLabelProvider extends LabelProvider { /** * {@inheritDoc} */ public Image getImage( Object element ) { if ( element instanceof ObjectClass ) { return Activator.getDefault().getImage( PluginConstants.IMG_OBJECT_CLASS ); } // Default return null; } /** * {@inheritDoc} */ public String getText( Object element ) { 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( "ObjectClassSelectionDialogLabelProvider.None" ), new String[] { oc.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/dialogs/RenameProjectDialog.java
plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/dialogs/RenameProjectDialog.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 org.apache.directory.studio.schemaeditor.Activator; import org.eclipse.swt.widgets.Shell; /** * this dialog is used to rename a project. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class RenameProjectDialog extends AbstractRenameDialog { /** * Creates a new instance of RenameProjectDialog. * * @param originalName * the original name of the project */ public RenameProjectDialog( String originalName ) { super( originalName ); } /** * {@inheritDoc} */ protected void configureShell( Shell newShell ) { super.configureShell( newShell ); newShell.setText( Messages.getString( "RenameProjectDialog.Rename" ) ); //$NON-NLS-1$ } /** * {@inheritDoc} */ protected String getErrorMessage() { return Messages.getString( "RenameProjectDialog.NameExists" ); //$NON-NLS-1$ } /** * {@inheritDoc} */ protected boolean isNewNameAlreadyTaken() { return Activator.getDefault().getProjectsHandler().isProjectNameAlreadyTaken( getNewName() ); } }
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/preferences/SchemaViewPreferencePage.java
plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/preferences/SchemaViewPreferencePage.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.preferences; import org.apache.directory.studio.schemaeditor.Activator; import org.apache.directory.studio.schemaeditor.PluginConstants; import org.eclipse.jface.preference.IPreferenceStore; import org.eclipse.jface.preference.PreferencePage; import org.eclipse.swt.SWT; 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.Control; import org.eclipse.swt.widgets.Group; import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Text; import org.eclipse.ui.IWorkbench; import org.eclipse.ui.IWorkbenchPreferencePage; /** * This class implements the Preference page for the Schema View * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class SchemaViewPreferencePage extends PreferencePage implements IWorkbenchPreferencePage { /** The preference page ID */ public static final String ID = PluginConstants.PREF_PAGE_SCHEMA_VIEW_ID; // UI fields private Combo labelCombo; private Button limitButton; private Text lengthText; private Button secondaryLabelButtonDisplay; private Combo secondaryLabelCombo; private Button secondaryLabelLimitButton; private Text secondaryLabelLengthText; private Button schemaLabelButtonDisplay; /** * Creates a new instance of SchemaViewPreferencePage. */ public SchemaViewPreferencePage() { super(); setPreferenceStore( Activator.getDefault().getPreferenceStore() ); setDescription( Messages.getString( "SchemaViewPreferencePage.GeneralSettings" ) ); //$NON-NLS-1$ } /** * {@inheritDoc} */ protected Control createContents( Composite parent ) { Composite composite = new Composite( parent, SWT.NONE ); composite.setLayout( new GridLayout() ); composite.setLayoutData( new GridData( SWT.FILL, SWT.FILL, true, true ) ); // Label Group Group labelGroup = new Group( composite, SWT.NONE ); labelGroup.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) ); labelGroup.setText( Messages.getString( "SchemaViewPreferencePage.Label" ) ); //$NON-NLS-1$ labelGroup.setLayout( new GridLayout() ); Composite labelGroupComposite = new Composite( labelGroup, SWT.NONE ); GridLayout gl = new GridLayout( 1, false ); gl.marginHeight = gl.marginWidth = 0; labelGroupComposite.setLayout( gl ); labelGroupComposite.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) ); // Label row composite Composite labelComposite = new Composite( labelGroupComposite, SWT.NONE ); gl = new GridLayout( 3, false ); gl.marginHeight = gl.marginWidth = 0; labelComposite.setLayout( gl ); GridData gd = new GridData( SWT.FILL, SWT.NONE, true, false ); gd.horizontalSpan = 1; labelComposite.setLayoutData( gd ); // Use Label Label useLabel = new Label( labelComposite, SWT.NONE ); useLabel.setText( Messages.getString( "SchemaViewPreferencePage.Use" ) ); //$NON-NLS-1$ // Label Combo labelCombo = new Combo( labelComposite, SWT.DROP_DOWN | SWT.READ_ONLY | SWT.BORDER ); labelCombo.setLayoutData( new GridData() ); labelCombo .setItems( new String[] { Messages.getString( "SchemaViewPreferencePage.FirstName" ), Messages.getString( "SchemaViewPreferencePage.AllAliases" ), Messages.getString( "SchemaViewPreferencePage.OID" ) } ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ labelCombo.setEnabled( true ); // As label Label Label asLabel = new Label( labelComposite, SWT.NONE ); asLabel.setText( Messages.getString( "SchemaViewPreferencePage.AsLabel" ) ); //$NON-NLS-1$ // Abbreviate row composite Composite abbreviateComposite = new Composite( labelGroupComposite, SWT.NONE ); gl = new GridLayout( 3, false ); gl.marginHeight = gl.marginWidth = 0; abbreviateComposite.setLayout( gl ); gd = new GridData( SWT.FILL, SWT.NONE, true, false ); gd.horizontalSpan = 1; abbreviateComposite.setLayoutData( gd ); // Limit label lenght to Label limitButton = new Button( abbreviateComposite, SWT.CHECK ); limitButton.setText( Messages.getString( "SchemaViewPreferencePage.LimitLabel" ) ); //$NON-NLS-1$ gd = new GridData(); gd.horizontalSpan = 1; limitButton.setLayoutData( gd ); // Lenght Text lengthText = new Text( abbreviateComposite, SWT.NONE | SWT.BORDER ); GridData gridData = new GridData(); gridData.horizontalSpan = 1; gridData.widthHint = 9 * 3; lengthText.setLayoutData( gridData ); lengthText.setTextLimit( 3 ); lengthText.addVerifyListener( new VerifyListener() { public void verifyText( VerifyEvent e ) { if ( !e.text.matches( "[0-9]*" ) ) //$NON-NLS-1$ { e.doit = false; } if ( "".equals( lengthText.getText() ) && e.text.matches( "[0]" ) ) //$NON-NLS-1$ //$NON-NLS-2$ { e.doit = false; } } } ); // Characters Label Label charactersLabel = new Label( abbreviateComposite, SWT.NONE ); charactersLabel.setText( Messages.getString( "SchemaViewPreferencePage.Characters" ) ); //$NON-NLS-1$ // Secondary Label Group Group secondaryLabelGroup = new Group( composite, SWT.NONE ); secondaryLabelGroup.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) ); secondaryLabelGroup.setText( Messages.getString( "SchemaViewPreferencePage.SecondaryLabel" ) ); //$NON-NLS-1$ secondaryLabelGroup.setLayout( new GridLayout() ); Composite secondaryLabelGroupComposite = new Composite( secondaryLabelGroup, SWT.NONE ); gl = new GridLayout( 1, false ); gl.marginHeight = gl.marginWidth = 0; secondaryLabelGroupComposite.setLayout( gl ); secondaryLabelGroupComposite.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) ); secondaryLabelButtonDisplay = new Button( secondaryLabelGroupComposite, SWT.CHECK ); secondaryLabelButtonDisplay.setText( Messages.getString( "SchemaViewPreferencePage.DisplaySecondaryLabel" ) ); //$NON-NLS-1$ // Label row composite Composite secondaryLabelComposite = new Composite( secondaryLabelGroupComposite, SWT.NONE ); gl = new GridLayout( 3, false ); gl.marginHeight = gl.marginWidth = 0; secondaryLabelComposite.setLayout( gl ); gd = new GridData( SWT.FILL, SWT.NONE, true, false ); gd.horizontalSpan = 1; secondaryLabelComposite.setLayoutData( gd ); // Use Label Label useLabel2 = new Label( secondaryLabelComposite, SWT.NONE ); useLabel2.setText( Messages.getString( "SchemaViewPreferencePage.Use" ) ); //$NON-NLS-1$ // Label Combo secondaryLabelCombo = new Combo( secondaryLabelComposite, SWT.DROP_DOWN | SWT.READ_ONLY | SWT.BORDER ); secondaryLabelCombo.setLayoutData( new GridData() ); secondaryLabelCombo .setItems( new String[] { Messages.getString( "SchemaViewPreferencePage.FirstName" ), Messages.getString( "SchemaViewPreferencePage.AllAliases" ), Messages.getString( "SchemaViewPreferencePage.OID" ) } ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ secondaryLabelCombo.setEnabled( true ); // As label Label Label asLabel2 = new Label( secondaryLabelComposite, SWT.NONE ); asLabel2.setText( Messages.getString( "SchemaViewPreferencePage.AsSecondaryLabel" ) ); //$NON-NLS-1$ // Abbreviate row composite Composite abbreviateComposite2 = new Composite( secondaryLabelGroup, SWT.NONE ); gl = new GridLayout( 3, false ); gl.marginHeight = gl.marginWidth = 0; abbreviateComposite2.setLayout( gl ); gd = new GridData( SWT.FILL, SWT.NONE, true, false ); gd.horizontalSpan = 1; abbreviateComposite2.setLayoutData( gd ); // Limit label lenght to Label secondaryLabelLimitButton = new Button( abbreviateComposite2, SWT.CHECK ); secondaryLabelLimitButton.setText( Messages.getString( "SchemaViewPreferencePage.LimitSecondaryLabel" ) ); //$NON-NLS-1$ gd = new GridData(); gd.horizontalSpan = 1; secondaryLabelLimitButton.setLayoutData( gd ); // Lenght Text secondaryLabelLengthText = new Text( abbreviateComposite2, SWT.NONE | SWT.BORDER ); gridData = new GridData(); gridData.horizontalSpan = 1; gridData.widthHint = 9 * 3; secondaryLabelLengthText.setLayoutData( gridData ); secondaryLabelLengthText.setTextLimit( 3 ); secondaryLabelLengthText.addVerifyListener( new VerifyListener() { public void verifyText( VerifyEvent e ) { if ( !e.text.matches( "[0-9]*" ) ) //$NON-NLS-1$ { e.doit = false; } if ( "".equals( secondaryLabelLengthText.getText() ) && e.text.matches( "[0]" ) ) //$NON-NLS-1$ //$NON-NLS-2$ { e.doit = false; } } } ); // Schema Label Group Group schemaLabelGroup = new Group( composite, SWT.NONE ); schemaLabelGroup.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) ); schemaLabelGroup.setText( Messages.getString( "SchemaViewPreferencePage.SchemaLabel" ) ); //$NON-NLS-1$ schemaLabelGroup.setLayout( new GridLayout() ); Composite schemaLabelGroupComposite = new Composite( schemaLabelGroup, SWT.NONE ); gl = new GridLayout( 1, false ); gl.marginHeight = gl.marginWidth = 0; schemaLabelGroupComposite.setLayout( gl ); schemaLabelGroupComposite.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) ); schemaLabelButtonDisplay = new Button( schemaLabelGroupComposite, SWT.CHECK ); schemaLabelButtonDisplay.setText( Messages.getString( "SchemaViewPreferencePage.DisplaySchemaLabel" ) ); //$NON-NLS-1$ // Characters Label Label secondaryLabelcharactersLabel = new Label( abbreviateComposite2, SWT.NONE ); secondaryLabelcharactersLabel.setText( Messages.getString( "SchemaViewPreferencePage.Characters" ) ); //$NON-NLS-1$ initFieldsFromPreferences(); initListeners(); applyDialogFont( parent ); return parent; } /** * Initializes the fields from the preferences store. */ private void initFieldsFromPreferences() { IPreferenceStore store = Activator.getDefault().getPreferenceStore(); labelCombo.select( store.getInt( PluginConstants.PREFS_SCHEMA_VIEW_LABEL ) ); limitButton.setSelection( store.getBoolean( PluginConstants.PREFS_SCHEMA_VIEW_ABBREVIATE ) ); lengthText.setEnabled( limitButton.getSelection() ); lengthText.setText( store.getString( PluginConstants.PREFS_SCHEMA_VIEW_ABBREVIATE_MAX_LENGTH ) ); secondaryLabelButtonDisplay.setSelection( store .getBoolean( PluginConstants.PREFS_SCHEMA_VIEW_SECONDARY_LABEL_DISPLAY ) ); secondaryLabelCombo.select( store.getInt( PluginConstants.PREFS_SCHEMA_VIEW_SECONDARY_LABEL ) ); secondaryLabelLimitButton.setSelection( store .getBoolean( PluginConstants.PREFS_SCHEMA_VIEW_SECONDARY_LABEL_ABBREVIATE ) ); secondaryLabelLengthText.setText( store .getString( PluginConstants.PREFS_SCHEMA_VIEW_SECONDARY_LABEL_ABBREVIATE_MAX_LENGTH ) ); if ( store.getBoolean( PluginConstants.PREFS_SCHEMA_VIEW_SECONDARY_LABEL_DISPLAY ) ) { secondaryLabelCombo.setEnabled( true ); secondaryLabelLimitButton.setEnabled( true ); secondaryLabelLengthText.setEnabled( secondaryLabelLimitButton.getSelection() ); } else { secondaryLabelCombo.setEnabled( false ); secondaryLabelLimitButton.setEnabled( false ); secondaryLabelLengthText.setEnabled( false ); } schemaLabelButtonDisplay.setSelection( store .getBoolean( PluginConstants.PREFS_SCHEMA_VIEW_SCHEMA_LABEL_DISPLAY ) ); } /** * Initializes the listeners. */ private void initListeners() { limitButton.addSelectionListener( new SelectionAdapter() { public void widgetSelected( SelectionEvent e ) { lengthText.setEnabled( limitButton.getSelection() ); } } ); secondaryLabelButtonDisplay.addSelectionListener( new SelectionAdapter() { public void widgetSelected( SelectionEvent e ) { if ( secondaryLabelButtonDisplay.getSelection() ) { secondaryLabelCombo.setEnabled( true ); secondaryLabelLimitButton.setEnabled( true ); secondaryLabelLengthText.setEnabled( secondaryLabelLimitButton.getSelection() ); } else { secondaryLabelCombo.setEnabled( false ); secondaryLabelLimitButton.setEnabled( false ); secondaryLabelLengthText.setEnabled( false ); } } } ); secondaryLabelLimitButton.addSelectionListener( new SelectionAdapter() { public void widgetSelected( SelectionEvent e ) { secondaryLabelLengthText.setEnabled( secondaryLabelLimitButton.getSelection() ); } } ); } /** * {@inheritDoc} */ protected void performDefaults() { IPreferenceStore store = Activator.getDefault().getPreferenceStore(); labelCombo.select( store.getDefaultInt( PluginConstants.PREFS_SCHEMA_VIEW_LABEL ) ); limitButton.setSelection( store.getDefaultBoolean( PluginConstants.PREFS_SCHEMA_VIEW_ABBREVIATE ) ); lengthText.setEnabled( limitButton.getSelection() ); lengthText.setText( store.getDefaultString( PluginConstants.PREFS_SCHEMA_VIEW_ABBREVIATE_MAX_LENGTH ) ); secondaryLabelButtonDisplay.setSelection( store .getDefaultBoolean( PluginConstants.PREFS_SCHEMA_VIEW_SECONDARY_LABEL_DISPLAY ) ); secondaryLabelCombo.select( store.getDefaultInt( PluginConstants.PREFS_SCHEMA_VIEW_SECONDARY_LABEL ) ); secondaryLabelLimitButton.setSelection( store .getDefaultBoolean( PluginConstants.PREFS_SCHEMA_VIEW_SECONDARY_LABEL_ABBREVIATE ) ); secondaryLabelLengthText.setText( store .getDefaultString( PluginConstants.PREFS_SCHEMA_VIEW_SECONDARY_LABEL_ABBREVIATE_MAX_LENGTH ) ); if ( secondaryLabelButtonDisplay.getSelection() ) { secondaryLabelCombo.setEnabled( true ); secondaryLabelLimitButton.setEnabled( true ); secondaryLabelLengthText.setEnabled( secondaryLabelLimitButton.getSelection() ); } else { secondaryLabelCombo.setEnabled( false ); secondaryLabelLimitButton.setEnabled( false ); secondaryLabelLengthText.setEnabled( false ); } schemaLabelButtonDisplay.setSelection( store .getDefaultBoolean( PluginConstants.PREFS_SCHEMA_VIEW_SCHEMA_LABEL_DISPLAY ) ); super.performDefaults(); } /** * {@inheritDoc} */ public boolean performOk() { IPreferenceStore store = Activator.getDefault().getPreferenceStore(); if ( labelCombo.getItem( labelCombo.getSelectionIndex() ).equals( Messages.getString( "SchemaViewPreferencePage.FirstName" ) ) ) //$NON-NLS-1$ { store .setValue( PluginConstants.PREFS_SCHEMA_VIEW_LABEL, PluginConstants.PREFS_SCHEMA_VIEW_LABEL_FIRST_NAME ); } else if ( labelCombo.getItem( labelCombo.getSelectionIndex() ).equals( Messages.getString( "SchemaViewPreferencePage.AllAliases" ) ) ) //$NON-NLS-1$ { store.setValue( PluginConstants.PREFS_SCHEMA_VIEW_LABEL, PluginConstants.PREFS_SCHEMA_VIEW_LABEL_ALL_ALIASES ); } else if ( labelCombo.getItem( labelCombo.getSelectionIndex() ).equals( Messages.getString( "SchemaViewPreferencePage.OID" ) ) ) //$NON-NLS-1$ { store.setValue( PluginConstants.PREFS_SCHEMA_VIEW_LABEL, PluginConstants.PREFS_SCHEMA_VIEW_LABEL_OID ); } store.setValue( PluginConstants.PREFS_SCHEMA_VIEW_ABBREVIATE, limitButton.getSelection() ); store.setValue( PluginConstants.PREFS_SCHEMA_VIEW_ABBREVIATE_MAX_LENGTH, lengthText.getText() ); store.setValue( PluginConstants.PREFS_SCHEMA_VIEW_SECONDARY_LABEL_DISPLAY, secondaryLabelButtonDisplay .getSelection() ); if ( secondaryLabelCombo.getItem( secondaryLabelCombo.getSelectionIndex() ).equals( Messages.getString( "SchemaViewPreferencePage.FirstName" ) ) ) //$NON-NLS-1$ { store.setValue( PluginConstants.PREFS_SCHEMA_VIEW_SECONDARY_LABEL, PluginConstants.PREFS_SCHEMA_VIEW_LABEL_FIRST_NAME ); } else if ( secondaryLabelCombo.getItem( secondaryLabelCombo.getSelectionIndex() ).equals( Messages.getString( "SchemaViewPreferencePage.AllAliases" ) ) ) //$NON-NLS-1$ { store.setValue( PluginConstants.PREFS_SCHEMA_VIEW_SECONDARY_LABEL, PluginConstants.PREFS_SCHEMA_VIEW_LABEL_ALL_ALIASES ); } else if ( secondaryLabelCombo.getItem( secondaryLabelCombo.getSelectionIndex() ).equals( Messages.getString( "SchemaViewPreferencePage.OID" ) ) ) //$NON-NLS-1$ { store.setValue( PluginConstants.PREFS_SCHEMA_VIEW_SECONDARY_LABEL, PluginConstants.PREFS_SCHEMA_VIEW_LABEL_OID ); } store.setValue( PluginConstants.PREFS_SCHEMA_VIEW_SECONDARY_LABEL_ABBREVIATE, secondaryLabelLimitButton .getSelection() ); store.setValue( PluginConstants.PREFS_SCHEMA_VIEW_SECONDARY_LABEL_ABBREVIATE_MAX_LENGTH, secondaryLabelLengthText.getText() ); store .setValue( PluginConstants.PREFS_SCHEMA_VIEW_SCHEMA_LABEL_DISPLAY, schemaLabelButtonDisplay.getSelection() ); return true; } /** * {@inheritDoc} */ public void init( IWorkbench workbench ) { // Nothing to do } }
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/preferences/Messages.java
plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/preferences/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.preferences; 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/preferences/SearchViewPreferencePage.java
plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/preferences/SearchViewPreferencePage.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.preferences; import org.apache.directory.studio.schemaeditor.Activator; import org.apache.directory.studio.schemaeditor.PluginConstants; import org.eclipse.jface.preference.IPreferenceStore; import org.eclipse.jface.preference.PreferencePage; import org.eclipse.swt.SWT; 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.Control; import org.eclipse.swt.widgets.Group; import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Text; import org.eclipse.ui.IWorkbench; import org.eclipse.ui.IWorkbenchPreferencePage; /** * This class implements the Preference page for the Search View * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class SearchViewPreferencePage extends PreferencePage implements IWorkbenchPreferencePage { /** The preference page ID */ public static final String ID = PluginConstants.PREF_PAGE_SEARCH_VIEW_ID; // UI fields private Combo labelCombo; private Button limitButton; private Text lengthText; private Button secondaryLabelButtonDisplay; private Combo secondaryLabelCombo; private Button secondaryLabelLimitButton; private Text secondaryLabelLengthText; private Button schemaLabelButtonDisplay; /** * Creates a new instance of SchemaViewPreferencePage. */ public SearchViewPreferencePage() { super(); setPreferenceStore( Activator.getDefault().getPreferenceStore() ); setDescription( Messages.getString( "SearchViewPreferencePage.GeneralSettings" ) ); //$NON-NLS-1$ } /** * {@inheritDoc} */ protected Control createContents( Composite parent ) { Composite composite = new Composite( parent, SWT.NONE ); composite.setLayout( new GridLayout() ); composite.setLayoutData( new GridData( SWT.FILL, SWT.FILL, true, true ) ); // Label Group Group labelGroup = new Group( composite, SWT.NONE ); labelGroup.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) ); labelGroup.setText( Messages.getString( "SearchViewPreferencePage.Label" ) ); //$NON-NLS-1$ labelGroup.setLayout( new GridLayout() ); Composite labelGroupComposite = new Composite( labelGroup, SWT.NONE ); GridLayout gl = new GridLayout( 1, false ); gl.marginHeight = gl.marginWidth = 0; labelGroupComposite.setLayout( gl ); labelGroupComposite.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) ); // Label row composite Composite labelComposite = new Composite( labelGroupComposite, SWT.NONE ); gl = new GridLayout( 3, false ); gl.marginHeight = gl.marginWidth = 0; labelComposite.setLayout( gl ); GridData gd = new GridData( SWT.FILL, SWT.NONE, true, false ); gd.horizontalSpan = 1; labelComposite.setLayoutData( gd ); // Use Label Label useLabel = new Label( labelComposite, SWT.NONE ); useLabel.setText( Messages.getString( "SearchViewPreferencePage.Use" ) ); //$NON-NLS-1$ // Label Combo labelCombo = new Combo( labelComposite, SWT.DROP_DOWN | SWT.READ_ONLY | SWT.BORDER ); labelCombo.setLayoutData( new GridData() ); labelCombo .setItems( new String[] { Messages.getString( "SearchViewPreferencePage.FirstName" ), Messages.getString( "SearchViewPreferencePage.AllAliases" ), Messages.getString( "SearchViewPreferencePage.OID" ) } ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ labelCombo.setEnabled( true ); // As label Label Label asLabel = new Label( labelComposite, SWT.NONE ); asLabel.setText( Messages.getString( "SearchViewPreferencePage.AsLabel" ) ); //$NON-NLS-1$ // Abbreviate row composite Composite abbreviateComposite = new Composite( labelGroupComposite, SWT.NONE ); gl = new GridLayout( 3, false ); gl.marginHeight = gl.marginWidth = 0; abbreviateComposite.setLayout( gl ); gd = new GridData( SWT.FILL, SWT.NONE, true, false ); gd.horizontalSpan = 1; abbreviateComposite.setLayoutData( gd ); // Limit label lenght to Label limitButton = new Button( abbreviateComposite, SWT.CHECK ); limitButton.setText( Messages.getString( "SearchViewPreferencePage.LimitLength" ) ); //$NON-NLS-1$ gd = new GridData(); gd.horizontalSpan = 1; limitButton.setLayoutData( gd ); // Lenght Text lengthText = new Text( abbreviateComposite, SWT.NONE | SWT.BORDER ); GridData gridData = new GridData(); gridData.horizontalSpan = 1; gridData.widthHint = 9 * 3; lengthText.setLayoutData( gridData ); lengthText.setTextLimit( 3 ); lengthText.addVerifyListener( new VerifyListener() { public void verifyText( VerifyEvent e ) { if ( !e.text.matches( "[0-9]*" ) ) //$NON-NLS-1$ { e.doit = false; } if ( "".equals( lengthText.getText() ) && e.text.matches( "[0]" ) ) //$NON-NLS-1$ //$NON-NLS-2$ { e.doit = false; } } } ); // Characters Label Label charactersLabel = new Label( abbreviateComposite, SWT.NONE ); charactersLabel.setText( Messages.getString( "SearchViewPreferencePage.Characters" ) ); //$NON-NLS-1$ // Secondary Label Group Group secondaryLabelGroup = new Group( composite, SWT.NONE ); secondaryLabelGroup.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) ); secondaryLabelGroup.setText( Messages.getString( "SearchViewPreferencePage.SecondaryLabel" ) ); //$NON-NLS-1$ secondaryLabelGroup.setLayout( new GridLayout() ); Composite secondaryLabelGroupComposite = new Composite( secondaryLabelGroup, SWT.NONE ); gl = new GridLayout( 1, false ); gl.marginHeight = gl.marginWidth = 0; secondaryLabelGroupComposite.setLayout( gl ); secondaryLabelGroupComposite.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) ); secondaryLabelButtonDisplay = new Button( secondaryLabelGroupComposite, SWT.CHECK ); secondaryLabelButtonDisplay.setText( Messages.getString( "SearchViewPreferencePage.DisplaySecondaryLabel" ) ); //$NON-NLS-1$ // Label row composite Composite secondaryLabelComposite = new Composite( secondaryLabelGroupComposite, SWT.NONE ); gl = new GridLayout( 3, false ); gl.marginHeight = gl.marginWidth = 0; secondaryLabelComposite.setLayout( gl ); gd = new GridData( SWT.FILL, SWT.NONE, true, false ); gd.horizontalSpan = 1; secondaryLabelComposite.setLayoutData( gd ); // Use Label Label useLabel2 = new Label( secondaryLabelComposite, SWT.NONE ); useLabel2.setText( Messages.getString( "SearchViewPreferencePage.Use" ) ); //$NON-NLS-1$ // Label Combo secondaryLabelCombo = new Combo( secondaryLabelComposite, SWT.DROP_DOWN | SWT.READ_ONLY | SWT.BORDER ); secondaryLabelCombo.setLayoutData( new GridData() ); secondaryLabelCombo .setItems( new String[] { Messages.getString( "SearchViewPreferencePage.FirstName" ), Messages.getString( "SearchViewPreferencePage.AllAliases" ), Messages.getString( "SearchViewPreferencePage.OID" ) } ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ secondaryLabelCombo.setEnabled( true ); // As label Label Label asLabel2 = new Label( secondaryLabelComposite, SWT.NONE ); asLabel2.setText( Messages.getString( "SearchViewPreferencePage.AsSecondaryLabel" ) ); //$NON-NLS-1$ // Abbreviate row composite Composite abbreviateComposite2 = new Composite( secondaryLabelGroup, SWT.NONE ); gl = new GridLayout( 3, false ); gl.marginHeight = gl.marginWidth = 0; abbreviateComposite2.setLayout( gl ); gd = new GridData( SWT.FILL, SWT.NONE, true, false ); gd.horizontalSpan = 1; abbreviateComposite2.setLayoutData( gd ); // Limit label lenght to Label secondaryLabelLimitButton = new Button( abbreviateComposite2, SWT.CHECK ); secondaryLabelLimitButton.setText( Messages.getString( "SearchViewPreferencePage.LimitSecondaryLabel" ) ); //$NON-NLS-1$ gd = new GridData(); gd.horizontalSpan = 1; secondaryLabelLimitButton.setLayoutData( gd ); // Lenght Text secondaryLabelLengthText = new Text( abbreviateComposite2, SWT.NONE | SWT.BORDER ); gridData = new GridData(); gridData.horizontalSpan = 1; gridData.widthHint = 9 * 3; secondaryLabelLengthText.setLayoutData( gridData ); secondaryLabelLengthText.setTextLimit( 3 ); secondaryLabelLengthText.addVerifyListener( new VerifyListener() { public void verifyText( VerifyEvent e ) { if ( !e.text.matches( "[0-9]*" ) ) //$NON-NLS-1$ { e.doit = false; } if ( "".equals( secondaryLabelLengthText.getText() ) && e.text.matches( "[0]" ) ) //$NON-NLS-1$ //$NON-NLS-2$ { e.doit = false; } } } ); // Characters Label Label secondaryLabelcharactersLabel = new Label( abbreviateComposite2, SWT.NONE ); secondaryLabelcharactersLabel.setText( Messages.getString( "SearchViewPreferencePage.Characters" ) ); //$NON-NLS-1$ // Schema Label Group Group schemaLabelGroup = new Group( composite, SWT.NONE ); schemaLabelGroup.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) ); schemaLabelGroup.setText( Messages.getString( "SearchViewPreferencePage.SchemaLabel" ) ); //$NON-NLS-1$ schemaLabelGroup.setLayout( new GridLayout() ); Composite schemaLabelGroupComposite = new Composite( schemaLabelGroup, SWT.NONE ); gl = new GridLayout( 1, false ); gl.marginHeight = gl.marginWidth = 0; schemaLabelGroupComposite.setLayout( gl ); schemaLabelGroupComposite.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) ); schemaLabelButtonDisplay = new Button( schemaLabelGroupComposite, SWT.CHECK ); schemaLabelButtonDisplay.setText( Messages.getString( "SearchViewPreferencePage.DisplaySchemaLabel" ) ); //$NON-NLS-1$ initFieldsFromPreferences(); initListeners(); applyDialogFont( parent ); return parent; } /** * Initializes the fields from the preferences store. */ private void initFieldsFromPreferences() { IPreferenceStore store = Activator.getDefault().getPreferenceStore(); labelCombo.select( store.getInt( PluginConstants.PREFS_SEARCH_VIEW_LABEL ) ); limitButton.setSelection( store.getBoolean( PluginConstants.PREFS_SEARCH_VIEW_ABBREVIATE ) ); lengthText.setEnabled( limitButton.getSelection() ); lengthText.setText( store.getString( PluginConstants.PREFS_SEARCH_VIEW_ABBREVIATE_MAX_LENGTH ) ); secondaryLabelButtonDisplay.setSelection( store .getBoolean( PluginConstants.PREFS_SEARCH_VIEW_SECONDARY_LABEL_DISPLAY ) ); secondaryLabelCombo.select( store.getInt( PluginConstants.PREFS_SEARCH_VIEW_SECONDARY_LABEL ) ); secondaryLabelLimitButton.setSelection( store .getBoolean( PluginConstants.PREFS_SEARCH_VIEW_SECONDARY_LABEL_ABBREVIATE ) ); secondaryLabelLengthText.setText( store .getString( PluginConstants.PREFS_SEARCH_VIEW_SECONDARY_LABEL_ABBREVIATE_MAX_LENGTH ) ); if ( store.getBoolean( PluginConstants.PREFS_SEARCH_VIEW_SECONDARY_LABEL_DISPLAY ) ) { secondaryLabelCombo.setEnabled( true ); secondaryLabelLimitButton.setEnabled( true ); secondaryLabelLengthText.setEnabled( secondaryLabelLimitButton.getSelection() ); } else { secondaryLabelCombo.setEnabled( false ); secondaryLabelLimitButton.setEnabled( false ); secondaryLabelLengthText.setEnabled( false ); } schemaLabelButtonDisplay.setSelection( store .getBoolean( PluginConstants.PREFS_SEARCH_VIEW_SCHEMA_LABEL_DISPLAY ) ); } /** * Initializes the listeners. */ private void initListeners() { limitButton.addSelectionListener( new SelectionAdapter() { public void widgetSelected( SelectionEvent e ) { lengthText.setEnabled( limitButton.getSelection() ); } } ); secondaryLabelButtonDisplay.addSelectionListener( new SelectionAdapter() { public void widgetSelected( SelectionEvent e ) { if ( secondaryLabelButtonDisplay.getSelection() ) { secondaryLabelCombo.setEnabled( true ); secondaryLabelLimitButton.setEnabled( true ); secondaryLabelLengthText.setEnabled( secondaryLabelLimitButton.getSelection() ); } else { secondaryLabelCombo.setEnabled( false ); secondaryLabelLimitButton.setEnabled( false ); secondaryLabelLengthText.setEnabled( false ); } } } ); secondaryLabelLimitButton.addSelectionListener( new SelectionAdapter() { public void widgetSelected( SelectionEvent e ) { secondaryLabelLengthText.setEnabled( secondaryLabelLimitButton.getSelection() ); } } ); } /** * {@inheritDoc} */ protected void performDefaults() { IPreferenceStore store = Activator.getDefault().getPreferenceStore(); labelCombo.select( store.getDefaultInt( PluginConstants.PREFS_SEARCH_VIEW_LABEL ) ); limitButton.setSelection( store.getDefaultBoolean( PluginConstants.PREFS_SEARCH_VIEW_ABBREVIATE ) ); lengthText.setEnabled( limitButton.getSelection() ); lengthText.setText( store.getDefaultString( PluginConstants.PREFS_SEARCH_VIEW_ABBREVIATE_MAX_LENGTH ) ); secondaryLabelButtonDisplay.setSelection( store .getDefaultBoolean( PluginConstants.PREFS_SEARCH_VIEW_SECONDARY_LABEL_DISPLAY ) ); secondaryLabelCombo.select( store.getDefaultInt( PluginConstants.PREFS_SEARCH_VIEW_SECONDARY_LABEL ) ); secondaryLabelLimitButton.setSelection( store .getDefaultBoolean( PluginConstants.PREFS_SEARCH_VIEW_SECONDARY_LABEL_ABBREVIATE ) ); secondaryLabelLengthText.setText( store .getDefaultString( PluginConstants.PREFS_SEARCH_VIEW_SECONDARY_LABEL_ABBREVIATE_MAX_LENGTH ) ); if ( secondaryLabelButtonDisplay.getSelection() ) { secondaryLabelCombo.setEnabled( true ); secondaryLabelLimitButton.setEnabled( true ); secondaryLabelLengthText.setEnabled( secondaryLabelLimitButton.getSelection() ); } else { secondaryLabelCombo.setEnabled( false ); secondaryLabelLimitButton.setEnabled( false ); secondaryLabelLengthText.setEnabled( false ); } schemaLabelButtonDisplay.setSelection( store .getDefaultBoolean( PluginConstants.PREFS_SEARCH_VIEW_SCHEMA_LABEL_DISPLAY ) ); super.performDefaults(); } /** * {@inheritDoc} */ public boolean performOk() { IPreferenceStore store = Activator.getDefault().getPreferenceStore(); if ( labelCombo.getItem( labelCombo.getSelectionIndex() ).equals( Messages.getString( "SearchViewPreferencePage.FirstName" ) ) ) //$NON-NLS-1$ { store .setValue( PluginConstants.PREFS_SEARCH_VIEW_LABEL, PluginConstants.PREFS_SEARCH_VIEW_LABEL_FIRST_NAME ); } else if ( labelCombo.getItem( labelCombo.getSelectionIndex() ).equals( Messages.getString( "SearchViewPreferencePage.AllAliases" ) ) ) //$NON-NLS-1$ { store.setValue( PluginConstants.PREFS_SEARCH_VIEW_LABEL, PluginConstants.PREFS_SEARCH_VIEW_LABEL_ALL_ALIASES ); } else if ( labelCombo.getItem( labelCombo.getSelectionIndex() ).equals( Messages.getString( "SearchViewPreferencePage.OID" ) ) ) //$NON-NLS-1$ { store.setValue( PluginConstants.PREFS_SEARCH_VIEW_LABEL, PluginConstants.PREFS_SEARCH_VIEW_LABEL_OID ); } store.setValue( PluginConstants.PREFS_SEARCH_VIEW_ABBREVIATE, limitButton.getSelection() ); store.setValue( PluginConstants.PREFS_SEARCH_VIEW_ABBREVIATE_MAX_LENGTH, lengthText.getText() ); store.setValue( PluginConstants.PREFS_SEARCH_VIEW_SECONDARY_LABEL_DISPLAY, secondaryLabelButtonDisplay .getSelection() ); if ( secondaryLabelCombo.getItem( secondaryLabelCombo.getSelectionIndex() ).equals( Messages.getString( "SearchViewPreferencePage.FirstName" ) ) ) //$NON-NLS-1$ { store.setValue( PluginConstants.PREFS_SEARCH_VIEW_SECONDARY_LABEL, PluginConstants.PREFS_SEARCH_VIEW_LABEL_FIRST_NAME ); } else if ( secondaryLabelCombo.getItem( secondaryLabelCombo.getSelectionIndex() ).equals( Messages.getString( "SearchViewPreferencePage.AllAliases" ) ) ) //$NON-NLS-1$ { store.setValue( PluginConstants.PREFS_SEARCH_VIEW_SECONDARY_LABEL, PluginConstants.PREFS_SEARCH_VIEW_LABEL_ALL_ALIASES ); } else if ( secondaryLabelCombo.getItem( secondaryLabelCombo.getSelectionIndex() ).equals( Messages.getString( "SearchViewPreferencePage.OID" ) ) ) //$NON-NLS-1$ { store.setValue( PluginConstants.PREFS_SEARCH_VIEW_SECONDARY_LABEL, PluginConstants.PREFS_SEARCH_VIEW_LABEL_OID ); } store.setValue( PluginConstants.PREFS_SEARCH_VIEW_SECONDARY_LABEL_ABBREVIATE, secondaryLabelLimitButton .getSelection() ); store.setValue( PluginConstants.PREFS_SEARCH_VIEW_SECONDARY_LABEL_ABBREVIATE_MAX_LENGTH, secondaryLabelLengthText.getText() ); store .setValue( PluginConstants.PREFS_SEARCH_VIEW_SCHEMA_LABEL_DISPLAY, schemaLabelButtonDisplay.getSelection() ); return true; } /** * {@inheritDoc} */ public void init( IWorkbench workbench ) { // Nothing to do } }
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/preferences/HierarchyViewPreferencePage.java
plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/preferences/HierarchyViewPreferencePage.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.preferences; import org.apache.directory.studio.schemaeditor.Activator; import org.apache.directory.studio.schemaeditor.PluginConstants; import org.eclipse.jface.preference.IPreferenceStore; import org.eclipse.jface.preference.PreferencePage; import org.eclipse.swt.SWT; 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.Control; import org.eclipse.swt.widgets.Group; import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Text; import org.eclipse.ui.IWorkbench; import org.eclipse.ui.IWorkbenchPreferencePage; /** * This class implements the Preference page for the Hierarchy View * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class HierarchyViewPreferencePage extends PreferencePage implements IWorkbenchPreferencePage { /** The preference page ID */ public static final String ID = PluginConstants.PREF_PAGE_HIERARCHY_VIEW_ID; // UI fields private Combo labelCombo; private Button limitButton; private Text lengthText; private Button secondaryLabelButtonDisplay; private Combo secondaryLabelCombo; private Button secondaryLabelLimitButton; private Text secondaryLabelLengthText; /** * Creates a new instance of HierarchyViewPreferencePage. */ public HierarchyViewPreferencePage() { super(); super.setPreferenceStore( Activator.getDefault().getPreferenceStore() ); super.setDescription( Messages.getString( "HierarchyViewPreferencePage.GeneralSettings" ) ); //$NON-NLS-1$ } /** * {@inheritDoc} */ protected Control createContents( Composite parent ) { Composite composite = new Composite( parent, SWT.NONE ); composite.setLayout( new GridLayout() ); composite.setLayoutData( new GridData( SWT.FILL, SWT.FILL, true, true ) ); // Label Group Group labelGroup = new Group( composite, SWT.NONE ); labelGroup.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) ); labelGroup.setText( Messages.getString( "HierarchyViewPreferencePage.Label" ) ); //$NON-NLS-1$ labelGroup.setLayout( new GridLayout() ); Composite labelGroupComposite = new Composite( labelGroup, SWT.NONE ); GridLayout gl = new GridLayout( 1, false ); gl.marginHeight = gl.marginWidth = 0; labelGroupComposite.setLayout( gl ); labelGroupComposite.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) ); // Label row composite Composite labelComposite = new Composite( labelGroupComposite, SWT.NONE ); gl = new GridLayout( 3, false ); gl.marginHeight = gl.marginWidth = 0; labelComposite.setLayout( gl ); GridData gd = new GridData( SWT.FILL, SWT.NONE, true, false ); gd.horizontalSpan = 1; labelComposite.setLayoutData( gd ); // Use Label Label useLabel = new Label( labelComposite, SWT.NONE ); useLabel.setText( Messages.getString( "HierarchyViewPreferencePage.Use" ) ); //$NON-NLS-1$ // Label Combo labelCombo = new Combo( labelComposite, SWT.DROP_DOWN | SWT.READ_ONLY | SWT.BORDER ); labelCombo.setLayoutData( new GridData() ); labelCombo .setItems( new String[] { Messages.getString( "HierarchyViewPreferencePage.FirstName" ), Messages.getString( "HierarchyViewPreferencePage.AllAliases" ), Messages.getString( "HierarchyViewPreferencePage.OID" ) } ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ labelCombo.setEnabled( true ); // As label Label Label asLabel = new Label( labelComposite, SWT.NONE ); asLabel.setText( Messages.getString( "HierarchyViewPreferencePage.AsLabel" ) ); //$NON-NLS-1$ // Abbreviate row composite Composite abbreviateComposite = new Composite( labelGroupComposite, SWT.NONE ); gl = new GridLayout( 3, false ); gl.marginHeight = gl.marginWidth = 0; abbreviateComposite.setLayout( gl ); gd = new GridData( SWT.FILL, SWT.NONE, true, false ); gd.horizontalSpan = 1; abbreviateComposite.setLayoutData( gd ); // Limit label lenght to Label limitButton = new Button( abbreviateComposite, SWT.CHECK ); limitButton.setText( Messages.getString( "HierarchyViewPreferencePage.LimitLabel" ) ); //$NON-NLS-1$ gd = new GridData(); gd.horizontalSpan = 1; limitButton.setLayoutData( gd ); // Lenght Text lengthText = new Text( abbreviateComposite, SWT.NONE | SWT.BORDER ); GridData gridData = new GridData(); gridData.horizontalSpan = 1; gridData.widthHint = 9 * 3; lengthText.setLayoutData( gridData ); lengthText.setTextLimit( 3 ); lengthText.addVerifyListener( new VerifyListener() { public void verifyText( VerifyEvent e ) { if ( !e.text.matches( "[0-9]*" ) ) //$NON-NLS-1$ { e.doit = false; } if ( "".equals( lengthText.getText() ) && e.text.matches( "[0]" ) ) //$NON-NLS-1$ //$NON-NLS-2$ { e.doit = false; } } } ); // Characters Label Label charactersLabel = new Label( abbreviateComposite, SWT.NONE ); charactersLabel.setText( Messages.getString( "HierarchyViewPreferencePage.Characters" ) ); //$NON-NLS-1$ // Secondary Label Group Group secondaryLabelGroup = new Group( composite, SWT.NONE ); secondaryLabelGroup.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) ); secondaryLabelGroup.setText( Messages.getString( "HierarchyViewPreferencePage.SecondaryLabel" ) ); //$NON-NLS-1$ secondaryLabelGroup.setLayout( new GridLayout() ); Composite secondaryLabelGroupComposite = new Composite( secondaryLabelGroup, SWT.NONE ); gl = new GridLayout( 1, false ); gl.marginHeight = gl.marginWidth = 0; secondaryLabelGroupComposite.setLayout( gl ); secondaryLabelGroupComposite.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) ); secondaryLabelButtonDisplay = new Button( secondaryLabelGroupComposite, SWT.CHECK ); secondaryLabelButtonDisplay.setText( Messages.getString( "HierarchyViewPreferencePage.DisplaySecondaryLabel" ) ); //$NON-NLS-1$ // Label row composite Composite secondaryLabelComposite = new Composite( secondaryLabelGroupComposite, SWT.NONE ); gl = new GridLayout( 3, false ); gl.marginHeight = gl.marginWidth = 0; secondaryLabelComposite.setLayout( gl ); gd = new GridData( SWT.FILL, SWT.NONE, true, false ); gd.horizontalSpan = 1; secondaryLabelComposite.setLayoutData( gd ); // Use Label Label useLabel2 = new Label( secondaryLabelComposite, SWT.NONE ); useLabel2.setText( Messages.getString( "HierarchyViewPreferencePage.Use" ) ); //$NON-NLS-1$ // Label Combo secondaryLabelCombo = new Combo( secondaryLabelComposite, SWT.DROP_DOWN | SWT.READ_ONLY | SWT.BORDER ); secondaryLabelCombo.setLayoutData( new GridData() ); secondaryLabelCombo .setItems( new String[] { Messages.getString( "HierarchyViewPreferencePage.FirstName" ), Messages.getString( "HierarchyViewPreferencePage.AllAliases" ), Messages.getString( "HierarchyViewPreferencePage.OID" ) } ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ secondaryLabelCombo.setEnabled( true ); // As label Label Label asLabel2 = new Label( secondaryLabelComposite, SWT.NONE ); asLabel2.setText( Messages.getString( "HierarchyViewPreferencePage.AsSecondaryLabel" ) ); //$NON-NLS-1$ // Abbreviate row composite Composite abbreviateComposite2 = new Composite( secondaryLabelGroup, SWT.NONE ); gl = new GridLayout( 3, false ); gl.marginHeight = gl.marginWidth = 0; abbreviateComposite2.setLayout( gl ); gd = new GridData( SWT.FILL, SWT.NONE, true, false ); gd.horizontalSpan = 1; abbreviateComposite2.setLayoutData( gd ); // Limit label length to Label secondaryLabelLimitButton = new Button( abbreviateComposite2, SWT.CHECK ); secondaryLabelLimitButton.setText( Messages.getString( "HierarchyViewPreferencePage.LimitSecondaryLabel" ) ); //$NON-NLS-1$ gd = new GridData(); gd.horizontalSpan = 1; secondaryLabelLimitButton.setLayoutData( gd ); // Length Text secondaryLabelLengthText = new Text( abbreviateComposite2, SWT.NONE | SWT.BORDER ); gridData = new GridData(); gridData.horizontalSpan = 1; gridData.widthHint = 9 * 3; secondaryLabelLengthText.setLayoutData( gridData ); secondaryLabelLengthText.setTextLimit( 3 ); secondaryLabelLengthText.addVerifyListener( new VerifyListener() { public void verifyText( VerifyEvent e ) { if ( !e.text.matches( "[0-9]*" ) ) //$NON-NLS-1$ { e.doit = false; } if ( "".equals( secondaryLabelLengthText.getText() ) && e.text.matches( "[0]" ) ) //$NON-NLS-1$ //$NON-NLS-2$ { e.doit = false; } } } ); // Characters Label Label secondaryLabelcharactersLabel = new Label( abbreviateComposite2, SWT.NONE ); secondaryLabelcharactersLabel.setText( Messages.getString( "HierarchyViewPreferencePage.Characters" ) ); //$NON-NLS-1$ initFieldsFromPreferences(); initListeners(); applyDialogFont( parent ); return parent; } /** * Initializes the fields from the preferences store. */ private void initFieldsFromPreferences() { IPreferenceStore store = Activator.getDefault().getPreferenceStore(); labelCombo.select( store.getInt( PluginConstants.PREFS_HIERARCHY_VIEW_LABEL ) ); limitButton.setSelection( store.getBoolean( PluginConstants.PREFS_HIERARCHY_VIEW_ABBREVIATE ) ); lengthText.setEnabled( limitButton.getSelection() ); lengthText.setText( store.getString( PluginConstants.PREFS_HIERARCHY_VIEW_ABBREVIATE_MAX_LENGTH ) ); secondaryLabelButtonDisplay.setSelection( store .getBoolean( PluginConstants.PREFS_HIERARCHY_VIEW_SECONDARY_LABEL_DISPLAY ) ); secondaryLabelCombo.select( store.getInt( PluginConstants.PREFS_HIERARCHY_VIEW_SECONDARY_LABEL ) ); secondaryLabelLimitButton.setSelection( store .getBoolean( PluginConstants.PREFS_HIERARCHY_VIEW_SECONDARY_LABEL_ABBREVIATE ) ); secondaryLabelLengthText.setText( store .getString( PluginConstants.PREFS_HIERARCHY_VIEW_SECONDARY_LABEL_ABBREVIATE_MAX_LENGTH ) ); if ( store.getBoolean( PluginConstants.PREFS_HIERARCHY_VIEW_SECONDARY_LABEL_DISPLAY ) ) { secondaryLabelCombo.setEnabled( true ); secondaryLabelLimitButton.setEnabled( true ); secondaryLabelLengthText.setEnabled( secondaryLabelLimitButton.getSelection() ); } else { secondaryLabelCombo.setEnabled( false ); secondaryLabelLimitButton.setEnabled( false ); secondaryLabelLengthText.setEnabled( false ); } } /** * Initializes the listeners. */ private void initListeners() { limitButton.addSelectionListener( new SelectionAdapter() { public void widgetSelected( SelectionEvent e ) { lengthText.setEnabled( limitButton.getSelection() ); } } ); secondaryLabelButtonDisplay.addSelectionListener( new SelectionAdapter() { public void widgetSelected( SelectionEvent e ) { if ( secondaryLabelButtonDisplay.getSelection() ) { secondaryLabelCombo.setEnabled( true ); secondaryLabelLimitButton.setEnabled( true ); secondaryLabelLengthText.setEnabled( secondaryLabelLimitButton.getSelection() ); } else { secondaryLabelCombo.setEnabled( false ); secondaryLabelLimitButton.setEnabled( false ); secondaryLabelLengthText.setEnabled( false ); } } } ); secondaryLabelLimitButton.addSelectionListener( new SelectionAdapter() { public void widgetSelected( SelectionEvent e ) { secondaryLabelLengthText.setEnabled( secondaryLabelLimitButton.getSelection() ); } } ); } /** * {@inheritDoc} */ protected void performDefaults() { IPreferenceStore store = Activator.getDefault().getPreferenceStore(); labelCombo.select( store.getDefaultInt( PluginConstants.PREFS_HIERARCHY_VIEW_LABEL ) ); limitButton.setSelection( store.getDefaultBoolean( PluginConstants.PREFS_HIERARCHY_VIEW_ABBREVIATE ) ); lengthText.setEnabled( limitButton.getSelection() ); lengthText.setText( store.getDefaultString( PluginConstants.PREFS_HIERARCHY_VIEW_ABBREVIATE_MAX_LENGTH ) ); secondaryLabelButtonDisplay.setSelection( store .getDefaultBoolean( PluginConstants.PREFS_HIERARCHY_VIEW_SECONDARY_LABEL_DISPLAY ) ); secondaryLabelCombo.select( store.getDefaultInt( PluginConstants.PREFS_HIERARCHY_VIEW_SECONDARY_LABEL ) ); secondaryLabelLimitButton.setSelection( store .getDefaultBoolean( PluginConstants.PREFS_HIERARCHY_VIEW_SECONDARY_LABEL_ABBREVIATE ) ); secondaryLabelLengthText.setText( store .getDefaultString( PluginConstants.PREFS_HIERARCHY_VIEW_SECONDARY_LABEL_ABBREVIATE_MAX_LENGTH ) ); if ( secondaryLabelButtonDisplay.getSelection() ) { secondaryLabelCombo.setEnabled( true ); secondaryLabelLimitButton.setEnabled( true ); secondaryLabelLengthText.setEnabled( secondaryLabelLimitButton.getSelection() ); } else { secondaryLabelCombo.setEnabled( false ); secondaryLabelLimitButton.setEnabled( false ); secondaryLabelLengthText.setEnabled( false ); } super.performDefaults(); } /** * {@inheritDoc} */ public boolean performOk() { IPreferenceStore store = Activator.getDefault().getPreferenceStore(); if ( labelCombo.getItem( labelCombo.getSelectionIndex() ).equals( Messages.getString( "HierarchyViewPreferencePage.FirstName" ) ) ) //$NON-NLS-1$ { store.setValue( PluginConstants.PREFS_HIERARCHY_VIEW_LABEL, PluginConstants.PREFS_HIERARCHY_VIEW_LABEL_FIRST_NAME ); } else if ( labelCombo.getItem( labelCombo.getSelectionIndex() ).equals( Messages.getString( "HierarchyViewPreferencePage.AllAliases" ) ) ) //$NON-NLS-1$ { store.setValue( PluginConstants.PREFS_HIERARCHY_VIEW_LABEL, PluginConstants.PREFS_HIERARCHY_VIEW_LABEL_ALL_ALIASES ); } else if ( labelCombo.getItem( labelCombo.getSelectionIndex() ).equals( Messages.getString( "HierarchyViewPreferencePage.OID" ) ) ) //$NON-NLS-1$ { store.setValue( PluginConstants.PREFS_HIERARCHY_VIEW_LABEL, PluginConstants.PREFS_HIERARCHY_VIEW_LABEL_OID ); } store.setValue( PluginConstants.PREFS_HIERARCHY_VIEW_ABBREVIATE, limitButton.getSelection() ); store.setValue( PluginConstants.PREFS_HIERARCHY_VIEW_ABBREVIATE_MAX_LENGTH, lengthText.getText() ); store.setValue( PluginConstants.PREFS_HIERARCHY_VIEW_SECONDARY_LABEL_DISPLAY, secondaryLabelButtonDisplay .getSelection() ); if ( secondaryLabelCombo.getItem( secondaryLabelCombo.getSelectionIndex() ).equals( Messages.getString( "HierarchyViewPreferencePage.FirstName" ) ) ) //$NON-NLS-1$ { store.setValue( PluginConstants.PREFS_HIERARCHY_VIEW_SECONDARY_LABEL, PluginConstants.PREFS_HIERARCHY_VIEW_LABEL_FIRST_NAME ); } else if ( secondaryLabelCombo.getItem( secondaryLabelCombo.getSelectionIndex() ).equals( Messages.getString( "HierarchyViewPreferencePage.AllAliases" ) ) ) //$NON-NLS-1$ { store.setValue( PluginConstants.PREFS_HIERARCHY_VIEW_SECONDARY_LABEL, PluginConstants.PREFS_HIERARCHY_VIEW_LABEL_ALL_ALIASES ); } else if ( secondaryLabelCombo.getItem( secondaryLabelCombo.getSelectionIndex() ).equals( Messages.getString( "HierarchyViewPreferencePage.OID" ) ) ) //$NON-NLS-1$ { store.setValue( PluginConstants.PREFS_HIERARCHY_VIEW_SECONDARY_LABEL, PluginConstants.PREFS_HIERARCHY_VIEW_LABEL_OID ); } store.setValue( PluginConstants.PREFS_HIERARCHY_VIEW_SECONDARY_LABEL_ABBREVIATE, secondaryLabelLimitButton .getSelection() ); store.setValue( PluginConstants.PREFS_HIERARCHY_VIEW_SECONDARY_LABEL_ABBREVIATE_MAX_LENGTH, secondaryLabelLengthText.getText() ); return true; } /** * {@inheritDoc} */ public void init( IWorkbench workbench ) { } }
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/preferences/PluginPreferencePage.java
plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/preferences/PluginPreferencePage.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.preferences; import java.util.Comparator; 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.model.io.SchemaConnector; import org.eclipse.jface.preference.PreferencePage; import org.eclipse.jface.viewers.ArrayContentProvider; import org.eclipse.jface.viewers.ISelectionChangedListener; import org.eclipse.jface.viewers.LabelProvider; import org.eclipse.jface.viewers.SelectionChangedEvent; import org.eclipse.jface.viewers.StructuredSelection; import org.eclipse.jface.viewers.TableViewer; import org.eclipse.jface.viewers.ViewerComparator; import org.eclipse.swt.SWT; import org.eclipse.swt.graphics.Image; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; 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.Text; import org.eclipse.ui.IWorkbench; import org.eclipse.ui.IWorkbenchPreferencePage; /** * This class implements the Preference page for the Plugin * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class PluginPreferencePage extends PreferencePage implements IWorkbenchPreferencePage { /** * Creates a new instance of PluginPreferencePage. * */ public PluginPreferencePage() { super(); setPreferenceStore( Activator.getDefault().getPreferenceStore() ); setDescription( Messages.getString( "PluginPreferencePage.GeneralSettings" ) ); //$NON-NLS-1$ } /** * {@inheritDoc} */ protected Control createContents( Composite parent ) { Composite composite = new Composite( parent, SWT.NONE ); composite.setLayout( new GridLayout() ); composite.setLayoutData( new GridData( SWT.FILL, SWT.FILL, true, true ) ); // SchemaConnectors Group Group schemaConnectorsGroup = new Group( composite, SWT.NONE ); schemaConnectorsGroup.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) ); schemaConnectorsGroup.setLayout( new GridLayout( 2, true ) ); schemaConnectorsGroup.setText( Messages.getString( "PluginPreferencePage.SchemaConnectors" ) ); //$NON-NLS-1$ // Available Schema Connectors Label Label availableSchemaConnectorsLabel = new Label( schemaConnectorsGroup, SWT.NONE ); availableSchemaConnectorsLabel.setText( Messages.getString( "PluginPreferencePage.AvailableConnectorsColon" ) ); //$NON-NLS-1$ // Description Label Label descriptionLabel = new Label( schemaConnectorsGroup, SWT.NONE ); descriptionLabel.setText( Messages.getString( "PluginPreferencePage.DescriptionColon" ) ); //$NON-NLS-1$ // SchemaConnectors TableViewer final TableViewer schemaConnectorsTableViewer = new TableViewer( schemaConnectorsGroup, SWT.BORDER | SWT.SINGLE | SWT.FULL_SELECTION ); GridData gridData = new GridData( SWT.FILL, SWT.NONE, true, false ); gridData.heightHint = 125; schemaConnectorsTableViewer.getTable().setLayoutData( gridData ); schemaConnectorsTableViewer.setContentProvider( new ArrayContentProvider() ); schemaConnectorsTableViewer.setLabelProvider( new LabelProvider() { public String getText( Object element ) { return ( ( SchemaConnector ) element ).getName(); } public Image getImage( Object element ) { return Activator.getDefault().getImage( PluginConstants.IMG_SCHEMA_CONNECTOR ); } } ); schemaConnectorsTableViewer.setComparator( new ViewerComparator( new Comparator<String>() { public int compare( String o1, String o2 ) { if ( ( o1 != null ) && ( o2 != null ) ) { return o1.compareToIgnoreCase( o2 ); } // Default return 0; } } ) ); // schemaConnectorsTableViewer.setComparator( new ViewerComparator( new Comparator<SchemaConnector>() // { // public int compare( SchemaConnector o1, SchemaConnector o2 ) // { // String name1 = o1.getName(); // String name2 = o2.getName(); // // if ( ( name1 != null ) && ( name2 != null ) ) // { // return name1.compareToIgnoreCase( name2 ); // } // // // Default // return 0; // } // } ) ); schemaConnectorsTableViewer.setInput( PluginUtils.getSchemaConnectors() ); // Description Text final Text descriptionText = new Text( schemaConnectorsGroup, SWT.BORDER | SWT.MULTI | SWT.READ_ONLY ); descriptionText.setLayoutData( new GridData( SWT.FILL, SWT.FILL, true, true ) ); schemaConnectorsTableViewer.addSelectionChangedListener( new ISelectionChangedListener() { public void selectionChanged( SelectionChangedEvent event ) { SchemaConnector schemaConnector = ( SchemaConnector ) ( ( StructuredSelection ) schemaConnectorsTableViewer .getSelection() ).getFirstElement(); if ( schemaConnector != null ) { descriptionText.setText( schemaConnector.getDescription() ); } } } ); return parent; } /** * {@inheritDoc} */ public void init( IWorkbench workbench ) { // Nothing to do } }
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/search/Messages.java
plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/search/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.search; 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/search/SearchPage.java
plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/search/SearchPage.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.search; import java.util.ArrayList; import java.util.Arrays; import java.util.List; 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.view.ViewUtils; import org.apache.directory.studio.schemaeditor.view.views.SearchView; import org.eclipse.jface.dialogs.DialogPage; import org.eclipse.jface.dialogs.IDialogSettings; import org.eclipse.search.ui.ISearchPage; import org.eclipse.search.ui.ISearchPageContainer; import org.eclipse.swt.SWT; import org.eclipse.swt.events.ModifyEvent; import org.eclipse.swt.events.ModifyListener; 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.Group; import org.eclipse.swt.widgets.Label; import org.eclipse.ui.PartInitException; /** * This class implements the Search Page. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class SearchPage extends DialogPage implements ISearchPage { /** The SearchPageContainer */ private ISearchPageContainer container; // UI Fields private Combo searchCombo; private Button aliasesButton; private Button oidButton; private Button descriptionButon; private Button superiorButton; private Button syntaxButton; private Button matchingRulesButton; private Button superiorsButton; private Button mandatoryAttributesButton; private Button optionalAttributesButton; private Button attributeTypesAndObjectClassesButton; private Button attributeTypesOnlyButton; private Button objectClassesOnly; /** * This enums represents the different possible search in for a Schema Search. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public enum SearchInEnum { ALIASES, OID, DESCRIPTION, SUPERIOR, SYNTAX, MATCHING_RULES, SUPERIORS, MANDATORY_ATTRIBUTES, OPTIONAL_ATTRIBUTES } /** * {@inheritDoc} */ public void createControl( Composite parent ) { parent.setLayout( new GridLayout() ); // Search String Label Label searchStringLabel = new Label( parent, SWT.NONE ); searchStringLabel.setText( Messages.getString( "SearchPage.SearchString" ) ); //$NON-NLS-1$ searchStringLabel.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) ); // Search Combo searchCombo = new Combo( parent, SWT.DROP_DOWN | SWT.BORDER ); searchCombo.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) ); searchCombo.addModifyListener( new ModifyListener() { public void modifyText( ModifyEvent arg0 ) { validate(); } } ); // Specific Scope Composite Composite searchInComposite = new Composite( parent, SWT.NONE ); GridLayout SearchInLayout = new GridLayout( 3, true ); SearchInLayout.marginBottom = 0; SearchInLayout.marginHeight = 0; SearchInLayout.marginLeft = 0; SearchInLayout.marginRight = 0; SearchInLayout.marginTop = 0; SearchInLayout.marginWidth = 0; searchInComposite.setLayout( SearchInLayout ); searchInComposite.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false, 3, 1 ) ); // Search In Group Group searchInGroup = new Group( searchInComposite, SWT.NONE ); searchInGroup.setLayout( new GridLayout() ); searchInGroup.setText( Messages.getString( "SearchPage.SearchIn" ) ); //$NON-NLS-1$ searchInGroup.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) ); // Aliases Button aliasesButton = new Button( searchInGroup, SWT.CHECK ); aliasesButton.setText( Messages.getString( "SearchPage.Aliases" ) ); //$NON-NLS-1$ // OID Button oidButton = new Button( searchInGroup, SWT.CHECK ); oidButton.setText( Messages.getString( "SearchPage.OID" ) ); //$NON-NLS-1$ // Description Button descriptionButon = new Button( searchInGroup, SWT.CHECK ); descriptionButon.setText( Messages.getString( "SearchPage.Description" ) ); //$NON-NLS-1$ // Attribute Types Group Group attributeTypesSearchInGroup = new Group( searchInComposite, SWT.NONE ); attributeTypesSearchInGroup.setText( Messages.getString( "SearchPage.SearchInForAttribute" ) ); //$NON-NLS-1$ attributeTypesSearchInGroup.setLayout( new GridLayout() ); attributeTypesSearchInGroup.setLayoutData( new GridData( SWT.FILL, SWT.FILL, true, true ) ); // Superior Button superiorButton = new Button( attributeTypesSearchInGroup, SWT.CHECK ); superiorButton.setText( Messages.getString( "SearchPage.Superior" ) ); //$NON-NLS-1$ // Syntax Button syntaxButton = new Button( attributeTypesSearchInGroup, SWT.CHECK ); syntaxButton.setText( Messages.getString( "SearchPage.Syntax" ) ); //$NON-NLS-1$ // Matching Rules Button matchingRulesButton = new Button( attributeTypesSearchInGroup, SWT.CHECK ); matchingRulesButton.setText( Messages.getString( "SearchPage.MatchingRules" ) ); //$NON-NLS-1$ // Object Classes Group Group objectClassesSearchInGroup = new Group( searchInComposite, SWT.NONE ); objectClassesSearchInGroup.setText( Messages.getString( "SearchPage.SearchInObject" ) ); //$NON-NLS-1$ objectClassesSearchInGroup.setLayout( new GridLayout() ); objectClassesSearchInGroup.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) ); // Superiors Button superiorsButton = new Button( objectClassesSearchInGroup, SWT.CHECK ); superiorsButton.setText( Messages.getString( "SearchPage.Superiors" ) ); //$NON-NLS-1$ // Mandatory Attributes Button mandatoryAttributesButton = new Button( objectClassesSearchInGroup, SWT.CHECK ); mandatoryAttributesButton.setText( Messages.getString( "SearchPage.MandatoryAttributes" ) ); //$NON-NLS-1$ // Optional Attributes Button optionalAttributesButton = new Button( objectClassesSearchInGroup, SWT.CHECK ); optionalAttributesButton.setText( Messages.getString( "SearchPage.OptionalAttributes" ) ); //$NON-NLS-1$ // Scope Group Group scopeGroup = new Group( parent, SWT.NONE ); scopeGroup.setText( Messages.getString( "SearchPage.Scope" ) ); //$NON-NLS-1$ scopeGroup.setLayout( new GridLayout() ); scopeGroup.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) ); // Attribute Types and Object Classes attributeTypesAndObjectClassesButton = new Button( scopeGroup, SWT.RADIO ); attributeTypesAndObjectClassesButton.setText( Messages.getString( "SearchPage.TypesAndClasses" ) ); //$NON-NLS-1$ // Attribute Types Only attributeTypesOnlyButton = new Button( scopeGroup, SWT.RADIO ); attributeTypesOnlyButton.setText( Messages.getString( "SearchPage.TypesOnly" ) ); //$NON-NLS-1$ // Object Classes Only objectClassesOnly = new Button( scopeGroup, SWT.RADIO ); objectClassesOnly.setText( Messages.getString( "SearchPage.ClassesOnly" ) ); //$NON-NLS-1$ initSearchStringHistory(); initSearchIn(); initSearchScope(); searchCombo.setFocus(); super.setControl( parent ); } /** * Initializes the Search String History. */ private void initSearchStringHistory() { searchCombo.setItems( loadSearchStringHistory() ); } /** * Initializes the Search In. */ private void initSearchIn() { IDialogSettings settings = Activator.getDefault().getDialogSettings(); if ( settings.get( PluginConstants.PREFS_SEARCH_PAGE_SEARCH_IN_ALIASES ) == null ) { aliasesButton.setSelection( true ); } else { aliasesButton.setSelection( settings.getBoolean( PluginConstants.PREFS_SEARCH_PAGE_SEARCH_IN_ALIASES ) ); } if ( settings.get( PluginConstants.PREFS_SEARCH_PAGE_SEARCH_IN_OID ) == null ) { oidButton.setSelection( true ); } else { oidButton.setSelection( settings.getBoolean( PluginConstants.PREFS_SEARCH_PAGE_SEARCH_IN_OID ) ); } if ( settings.get( PluginConstants.PREFS_SEARCH_PAGE_SEARCH_IN_DESCRIPTION ) == null ) { descriptionButon.setSelection( true ); } else { descriptionButon.setSelection( settings .getBoolean( PluginConstants.PREFS_SEARCH_PAGE_SEARCH_IN_DESCRIPTION ) ); } superiorButton.setSelection( settings.getBoolean( PluginConstants.PREFS_SEARCH_PAGE_SEARCH_IN_SUPERIOR ) ); syntaxButton.setSelection( settings.getBoolean( PluginConstants.PREFS_SEARCH_PAGE_SEARCH_IN_SYNTAX ) ); matchingRulesButton.setSelection( settings .getBoolean( PluginConstants.PREFS_SEARCH_PAGE_SEARCH_IN_MATCHING_RULES ) ); superiorsButton.setSelection( settings.getBoolean( PluginConstants.PREFS_SEARCH_PAGE_SEARCH_IN_SUPERIORS ) ); mandatoryAttributesButton.setSelection( settings .getBoolean( PluginConstants.PREFS_SEARCH_PAGE_SEARCH_IN_MANDATORY_ATTRIBUTES ) ); optionalAttributesButton.setSelection( settings .getBoolean( PluginConstants.PREFS_SEARCH_PAGE_SEARCH_IN_OPTIONAL_ATTRIBUTES ) ); } /** * Initializes the Search Scope. */ private void initSearchScope() { IDialogSettings settings = Activator.getDefault().getDialogSettings(); if ( settings.get( PluginConstants.PREFS_SEARCH_PAGE_SCOPE ) == null ) { attributeTypesAndObjectClassesButton.setSelection( true ); } else { switch ( settings.getInt( PluginConstants.PREFS_SEARCH_PAGE_SCOPE ) ) { case PluginConstants.PREFS_SEARCH_PAGE_SCOPE_AT_AND_OC: attributeTypesAndObjectClassesButton.setSelection( true ); break; case PluginConstants.PREFS_SEARCH_PAGE_SCOPE_AT_ONLY: attributeTypesOnlyButton.setSelection( true ); break; case PluginConstants.PREFS_SEARCH_PAGE_SCOPE_OC_ONLY: objectClassesOnly.setSelection( true ); break; } } } /** * {@inheritDoc} */ public boolean performAction() { // Search In List<SearchInEnum> searchIn = new ArrayList<SearchInEnum>(); if ( aliasesButton.getSelection() ) { searchIn.add( SearchInEnum.ALIASES ); } if ( oidButton.getSelection() ) { searchIn.add( SearchInEnum.OID ); } if ( descriptionButon.getSelection() ) { searchIn.add( SearchInEnum.DESCRIPTION ); } if ( superiorButton.getSelection() ) { searchIn.add( SearchInEnum.SUPERIOR ); } if ( syntaxButton.getSelection() ) { searchIn.add( SearchInEnum.SYNTAX ); } if ( matchingRulesButton.getSelection() ) { searchIn.add( SearchInEnum.MATCHING_RULES ); } if ( superiorsButton.getSelection() ) { searchIn.add( SearchInEnum.SUPERIORS ); } if ( mandatoryAttributesButton.getSelection() ) { searchIn.add( SearchInEnum.MANDATORY_ATTRIBUTES ); } if ( optionalAttributesButton.getSelection() ) { searchIn.add( SearchInEnum.OPTIONAL_ATTRIBUTES ); } // Scope int scope = 0; if ( attributeTypesAndObjectClassesButton.getSelection() ) { scope = PluginConstants.PREFS_SEARCH_PAGE_SCOPE_AT_AND_OC; } else if ( attributeTypesOnlyButton.getSelection() ) { scope = PluginConstants.PREFS_SEARCH_PAGE_SCOPE_AT_ONLY; } else if ( objectClassesOnly.getSelection() ) { scope = PluginConstants.PREFS_SEARCH_PAGE_SCOPE_OC_ONLY; } // Opening the SearchView and displaying the results try { SearchView searchView = ( SearchView ) Activator.getDefault().getWorkbench().getActiveWorkbenchWindow() .getActivePage().showView( SearchView.ID ); searchView.setSearchInput( searchCombo.getText(), searchIn.toArray( new SearchInEnum[0] ), scope ); } catch ( PartInitException e ) { PluginUtils.logError( Messages.getString( "SearchPage.ErrorOpeningView" ), e ); //$NON-NLS-1$ ViewUtils.displayErrorMessageDialog( Messages.getString( "SearchPage.Error" ), Messages.getString( "SearchPage.ErrorOpeningView" ) ); //$NON-NLS-1$ //$NON-NLS-2$ } return true; } /** * {@inheritDoc} */ public void setContainer( ISearchPageContainer container ) { this.container = container; } /** * {@inheritDoc} */ public void setVisible( boolean visible ) { validate(); super.setVisible( visible ); } /** * Verifies if the page is valid. * * @return * true if the page is valid */ private boolean isValid() { return ( ( searchCombo.getText() != null ) && ( !"".equals( searchCombo.getText() ) ) ); //$NON-NLS-1$ } /** * Validates the page. */ private void validate() { container.setPerformActionEnabled( isValid() ); } /** * Adds a new Search String to the History. * * @param value * the value to save */ public static void addSearchStringHistory( String value ) { // get current history String[] history = loadSearchStringHistory(); List<String> list = new ArrayList<String>( Arrays.asList( history ) ); // add new value or move to first position if ( list.contains( value ) ) { list.remove( value ); } list.add( 0, value ); // check history size while ( list.size() > 10 ) { list.remove( list.size() - 1 ); } // save history = ( String[] ) list.toArray( new String[list.size()] ); Activator.getDefault().getDialogSettings().put( PluginConstants.PREFS_SEARCH_PAGE_SEARCH_HISTORY, history ); } /** * Removes the given value from the History. * * @param value * the value to remove */ public static void removeSearchStringHistory( String value ) { // get current history String[] history = loadSearchStringHistory(); List<String> list = new ArrayList<String>( Arrays.asList( history ) ); // add new value or move to first position if ( list.contains( value ) ) { list.remove( value ); } // save history = ( String[] ) list.toArray( new String[list.size()] ); Activator.getDefault().getDialogSettings().put( PluginConstants.PREFS_SEARCH_PAGE_SEARCH_HISTORY, history ); } /** * Loads the Search History * * @return * an array of String containing the Search History */ public static String[] loadSearchStringHistory() { String[] history = Activator.getDefault().getDialogSettings().getArray( PluginConstants.PREFS_SEARCH_PAGE_SEARCH_HISTORY ); if ( history == null ) { history = new String[0]; } return history; } /** * Loads the Search In. * * @return * the search In */ public static List<SearchInEnum> loadSearchIn() { List<SearchInEnum> searchScope = new ArrayList<SearchInEnum>(); IDialogSettings settings = Activator.getDefault().getDialogSettings(); if ( settings.get( PluginConstants.PREFS_SEARCH_PAGE_SEARCH_IN_ALIASES ) == null ) { searchScope.add( SearchInEnum.ALIASES ); } else { if ( settings.getBoolean( PluginConstants.PREFS_SEARCH_PAGE_SEARCH_IN_ALIASES ) ) { searchScope.add( SearchInEnum.ALIASES ); } } if ( settings.get( PluginConstants.PREFS_SEARCH_PAGE_SEARCH_IN_OID ) == null ) { searchScope.add( SearchInEnum.OID ); } else { if ( settings.getBoolean( PluginConstants.PREFS_SEARCH_PAGE_SEARCH_IN_OID ) ) { searchScope.add( SearchInEnum.OID ); } } if ( settings.get( PluginConstants.PREFS_SEARCH_PAGE_SEARCH_IN_DESCRIPTION ) == null ) { searchScope.add( SearchInEnum.DESCRIPTION ); } else { if ( settings.getBoolean( PluginConstants.PREFS_SEARCH_PAGE_SEARCH_IN_DESCRIPTION ) ) { searchScope.add( SearchInEnum.DESCRIPTION ); } } if ( settings.getBoolean( PluginConstants.PREFS_SEARCH_PAGE_SEARCH_IN_SUPERIOR ) ) { searchScope.add( SearchInEnum.SUPERIOR ); } if ( settings.getBoolean( PluginConstants.PREFS_SEARCH_PAGE_SEARCH_IN_SYNTAX ) ) { searchScope.add( SearchInEnum.SYNTAX ); } if ( settings.getBoolean( PluginConstants.PREFS_SEARCH_PAGE_SEARCH_IN_MATCHING_RULES ) ) { searchScope.add( SearchInEnum.MATCHING_RULES ); } if ( settings.getBoolean( PluginConstants.PREFS_SEARCH_PAGE_SEARCH_IN_SUPERIORS ) ) { searchScope.add( SearchInEnum.SUPERIORS ); } if ( settings.getBoolean( PluginConstants.PREFS_SEARCH_PAGE_SEARCH_IN_MANDATORY_ATTRIBUTES ) ) { searchScope.add( SearchInEnum.MANDATORY_ATTRIBUTES ); } if ( settings.getBoolean( PluginConstants.PREFS_SEARCH_PAGE_SEARCH_IN_OPTIONAL_ATTRIBUTES ) ) { searchScope.add( SearchInEnum.OPTIONAL_ATTRIBUTES ); } return searchScope; } /** * Loads the scope. * * @return * the scope */ public static int loadScope() { IDialogSettings settings = Activator.getDefault().getDialogSettings(); if ( settings.get( PluginConstants.PREFS_SEARCH_PAGE_SCOPE ) == null ) { return PluginConstants.PREFS_SEARCH_PAGE_SCOPE_AT_AND_OC; } else { return settings.getInt( PluginConstants.PREFS_SEARCH_PAGE_SCOPE ); } } /** * Saves the Search scope. * * @param scope * the Search scope */ public static void saveSearchScope( List<SearchInEnum> scope ) { if ( ( scope != null ) && ( scope.size() > 0 ) ) { IDialogSettings settings = Activator.getDefault().getDialogSettings(); settings.put( PluginConstants.PREFS_SEARCH_PAGE_SEARCH_IN_ALIASES, scope.contains( SearchInEnum.ALIASES ) ); settings.put( PluginConstants.PREFS_SEARCH_PAGE_SEARCH_IN_OID, scope.contains( SearchInEnum.OID ) ); settings.put( PluginConstants.PREFS_SEARCH_PAGE_SEARCH_IN_DESCRIPTION, scope .contains( SearchInEnum.DESCRIPTION ) ); settings .put( PluginConstants.PREFS_SEARCH_PAGE_SEARCH_IN_SUPERIOR, scope.contains( SearchInEnum.SUPERIOR ) ); settings.put( PluginConstants.PREFS_SEARCH_PAGE_SEARCH_IN_SYNTAX, scope.contains( SearchInEnum.SYNTAX ) ); settings.put( PluginConstants.PREFS_SEARCH_PAGE_SEARCH_IN_MATCHING_RULES, scope .contains( SearchInEnum.MATCHING_RULES ) ); settings.put( PluginConstants.PREFS_SEARCH_PAGE_SEARCH_IN_SUPERIORS, scope .contains( SearchInEnum.SUPERIORS ) ); settings.put( PluginConstants.PREFS_SEARCH_PAGE_SEARCH_IN_MANDATORY_ATTRIBUTES, scope .contains( SearchInEnum.MANDATORY_ATTRIBUTES ) ); settings.put( PluginConstants.PREFS_SEARCH_PAGE_SEARCH_IN_OPTIONAL_ATTRIBUTES, scope .contains( SearchInEnum.OPTIONAL_ATTRIBUTES ) ); } } /** * Clears the Search History. */ public static void clearSearchHistory() { Activator.getDefault().getDialogSettings() .put( PluginConstants.PREFS_SEARCH_PAGE_SEARCH_HISTORY, new String[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/wizards/ImportCoreSchemasWizardPage.java
plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/wizards/ImportCoreSchemasWizardPage.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.wizards; import java.util.ArrayList; import java.util.List; 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.Schema; import org.apache.directory.studio.schemaeditor.view.widget.CoreSchemasSelectionWidget; import org.apache.directory.studio.schemaeditor.view.widget.CoreSchemasSelectionWidget.ServerTypeEnum; import org.eclipse.jface.wizard.WizardPage; import org.eclipse.swt.widgets.Composite; /** * This class represents the {@link WizardPage} of the {@link ImportCoreSchemasWizard}. * <p> * It is used to let the user choose the 'core' schemas to import. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class ImportCoreSchemasWizardPage extends AbstractWizardPage { // UI Fields private CoreSchemasSelectionWidget coreSchemaSelectionWidget; /** * Creates a new instance of ImportCoreSchemasWizardPage. */ protected ImportCoreSchemasWizardPage() { super( "ImportCoreSchemasWizardPage" ); //$NON-NLS-1$ setTitle( Messages.getString( "ImportCoreSchemasWizardPage.ImportCoreSchemas" ) ); //$NON-NLS-1$ setDescription( Messages.getString( "ImportCoreSchemasWizardPage.PleaseSelectCoreSchemas" ) ); //$NON-NLS-1$ setImageDescriptor( Activator.getDefault().getImageDescriptor( PluginConstants.IMG_SCHEMAS_IMPORT_WIZARD ) ); } /** * {@inheritDoc} */ public void createControl( Composite parent ) { coreSchemaSelectionWidget = new CoreSchemasSelectionWidget(); Composite composite = coreSchemaSelectionWidget.createWidget( parent ); coreSchemaSelectionWidget.init( ServerTypeEnum.APACHE_DS ); Project project = Activator.getDefault().getProjectsHandler().getOpenProject(); if ( project != null ) { List<Schema> schemas = project.getSchemaHandler().getSchemas(); List<String> schemaNames = new ArrayList<String>(); for ( Schema schema : schemas ) { schemaNames.add( schema.getSchemaName() ); } coreSchemaSelectionWidget.setGrayedCoreSchemas( schemaNames.toArray( new String[0] ) ); } dialogChanged(); setControl( composite ); } /** * This method is called when the user modifies something in the UI. */ private void dialogChanged() { // Checking if a Schema Project is open if ( Activator.getDefault().getSchemaHandler() == null ) { displayErrorMessage( Messages.getString( "ImportCoreSchemasWizardPage.ErrorNoSchemaProjectOpen" ) ); //$NON-NLS-1$ return; } displayErrorMessage( null ); } /** * Gets the schemas selected by the User. * * @return * the selected schemas */ public String[] getSelectedSchemas() { return coreSchemaSelectionWidget.getSelectedCoreSchemas(); } /** * Gets the Server Type * * @return * the Server Type */ public ServerTypeEnum getServerType() { return coreSchemaSelectionWidget.getServerType(); } }
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/wizards/NewObjectClassWizard.java
plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/wizards/NewObjectClassWizard.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.wizards; 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.model.Schema; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jface.wizard.Wizard; import org.eclipse.ui.INewWizard; import org.eclipse.ui.IWorkbench; /** * This class represents the wizard to create a new ObjectClass. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class NewObjectClassWizard extends Wizard implements INewWizard { public static final String ID = PluginConstants.NEW_WIZARD_NEW_OBJECT_CLASS_WIZARD; /** The selected schema */ private Schema selectedSchema; // The pages of the wizards private NewObjectClassGeneralPageWizardPage generalPage; private NewObjectClassContentWizardPage contentPage; private NewObjectClassMandatoryAttributesPage mandatoryAttributesPage; private NewObjectClassOptionalAttributesPage optionalAttributesPage; /** * {@inheritDoc} */ public void addPages() { // Creating pages generalPage = new NewObjectClassGeneralPageWizardPage(); generalPage.setSelectedSchema( selectedSchema ); contentPage = new NewObjectClassContentWizardPage(); mandatoryAttributesPage = new NewObjectClassMandatoryAttributesPage(); optionalAttributesPage = new NewObjectClassOptionalAttributesPage(); // Adding pages addPage( generalPage ); addPage( contentPage ); addPage( mandatoryAttributesPage ); addPage( optionalAttributesPage ); } /** * {@inheritDoc} */ public boolean performFinish() { // Creating the new object class ObjectClass newOC = new ObjectClass( generalPage.getOidValue() ); newOC.setSchemaName( generalPage.getSchemaValue() ); newOC.setNames( generalPage.getAliasesValue() ); newOC.setDescription( generalPage.getDescriptionValue() ); newOC.setSuperiorOids( contentPage.getSuperiorsNameValue() ); newOC.setType( contentPage.getClassTypeValue() ); newOC.setObsolete( contentPage.getObsoleteValue() ); newOC.setMustAttributeTypeOids( mandatoryAttributesPage.getMandatoryAttributeTypesNames() ); newOC.setMayAttributeTypeOids( optionalAttributesPage.getOptionalAttributeTypesNames() ); // Adding the new object class Activator.getDefault().getSchemaHandler().addObjectClass( newOC ); // Saving the Dialog Settings OID History PluginUtils.saveDialogSettingsHistory( PluginConstants.DIALOG_SETTINGS_OID_HISTORY, newOC.getOid() ); return true; } /** * {@inheritDoc} */ public void init( IWorkbench workbench, IStructuredSelection selection ) { // Nothing to do. } /** * Sets the selected schema. * * @param schema * the selected schema */ public void setSelectedSchema( Schema schema ) { selectedSchema = 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/wizards/ExportProjectsWizardPage.java
plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/wizards/ExportProjectsWizardPage.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.wizards; import java.io.File; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.List; 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.ProjectType; import org.eclipse.jface.viewers.ArrayContentProvider; import org.eclipse.jface.viewers.CheckStateChangedEvent; import org.eclipse.jface.viewers.CheckboxTableViewer; import org.eclipse.jface.viewers.ICheckStateListener; import org.eclipse.jface.viewers.LabelProvider; 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.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.DirectoryDialog; import org.eclipse.swt.widgets.Group; import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Table; import org.eclipse.swt.widgets.Text; import org.eclipse.ui.PlatformUI; /** * This class represents the WizardPage of the ExportProjectsWizard. * <p> * It is used to let the user enter the informations about the * schemas projects he wants to export and where to export. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class ExportProjectsWizardPage extends AbstractWizardPage { /** The selected projects */ private Project[] selectedProjects = new Project[0]; // UI Fields private CheckboxTableViewer projectsTableViewer; private Button projectsTableSelectAllButton; private Button projectsTableDeselectAllButton; private Label exportDirectoryLabel; private Text exportDirectoryText; private Button exportDirectoryButton; /** * Creates a new instance of ExportSchemasAsXmlWizardPage. */ protected ExportProjectsWizardPage() { super( "ExportProjectsWizardPage" ); //$NON-NLS-1$ setTitle( Messages.getString( "ExportProjectsWizardPage.ExportSchemaProjects" ) ); //$NON-NLS-1$ setDescription( Messages.getString( "ExportProjectsWizardPage.PleaseSelectSchemaProjects" ) ); //$NON-NLS-1$ setImageDescriptor( Activator.getDefault().getImageDescriptor( PluginConstants.IMG_PROJECT_EXPORT_WIZARD ) ); } /** * {@inheritDoc} */ public void createControl( Composite parent ) { Composite composite = new Composite( parent, SWT.NULL ); GridLayout layout = new GridLayout(); composite.setLayout( layout ); // Projects Group Group schemaProjectsGroup = new Group( composite, SWT.NONE ); schemaProjectsGroup.setText( Messages.getString( "ExportProjectsWizardPage.SchemaProjects" ) ); //$NON-NLS-1$ schemaProjectsGroup.setLayout( new GridLayout( 2, false ) ); schemaProjectsGroup.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) ); // Projects TableViewer Label projectsLabel = new Label( schemaProjectsGroup, SWT.NONE ); projectsLabel.setText( Messages.getString( "ExportProjectsWizardPage.SelectSchemaProjects" ) ); //$NON-NLS-1$ projectsLabel.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false, 2, 1 ) ); projectsTableViewer = new CheckboxTableViewer( new Table( schemaProjectsGroup, SWT.BORDER | SWT.CHECK | SWT.FULL_SELECTION ) ); GridData projectsTableViewerGridData = new GridData( SWT.FILL, SWT.NONE, true, false, 1, 2 ); projectsTableViewerGridData.heightHint = 125; projectsTableViewer.getTable().setLayoutData( projectsTableViewerGridData ); projectsTableViewer.setContentProvider( new ArrayContentProvider() ); projectsTableViewer.setLabelProvider( new LabelProvider() { public String getText( Object element ) { if ( element instanceof Project ) { return ( ( Project ) element ).getName(); } // Default return super.getText( element ); } public Image getImage( Object element ) { if ( element instanceof Project ) { ProjectType type = ( ( Project ) element ).getType(); switch ( type ) { case OFFLINE: return Activator.getDefault().getImage( PluginConstants.IMG_PROJECT_OFFLINE_CLOSED ); case ONLINE: return Activator.getDefault().getImage( PluginConstants.IMG_PROJECT_ONLINE_CLOSED ); } } // Default return super.getImage( element ); } } ); projectsTableViewer.addCheckStateListener( new ICheckStateListener() { /** * Notifies of a change to the checked state of an element. * * @param event * event object describing the change */ public void checkStateChanged( CheckStateChangedEvent event ) { dialogChanged(); } } ); projectsTableSelectAllButton = new Button( schemaProjectsGroup, SWT.PUSH ); projectsTableSelectAllButton.setText( Messages.getString( "ExportProjectsWizardPage.SelectAll" ) ); //$NON-NLS-1$ projectsTableSelectAllButton.setLayoutData( new GridData( SWT.FILL, SWT.BEGINNING, false, false ) ); projectsTableSelectAllButton.addSelectionListener( new SelectionAdapter() { public void widgetSelected( SelectionEvent e ) { projectsTableViewer.setAllChecked( true ); dialogChanged(); } } ); projectsTableDeselectAllButton = new Button( schemaProjectsGroup, SWT.PUSH ); projectsTableDeselectAllButton.setText( Messages.getString( "ExportProjectsWizardPage.DeselectAll" ) ); //$NON-NLS-1$ projectsTableDeselectAllButton.setLayoutData( new GridData( SWT.FILL, SWT.BEGINNING, false, false ) ); projectsTableDeselectAllButton.addSelectionListener( new SelectionAdapter() { public void widgetSelected( SelectionEvent e ) { projectsTableViewer.setAllChecked( false ); dialogChanged(); } } ); // Export Destination Group Group exportDestinationGroup = new Group( composite, SWT.NULL ); exportDestinationGroup.setText( Messages.getString( "ExportProjectsWizardPage.ExportDestination" ) ); //$NON-NLS-1$ exportDestinationGroup.setLayout( new GridLayout( 3, false ) ); exportDestinationGroup.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) ); exportDirectoryLabel = new Label( exportDestinationGroup, SWT.NONE ); exportDirectoryLabel.setText( Messages.getString( "ExportProjectsWizardPage.Directory" ) ); //$NON-NLS-1$ exportDirectoryText = new Text( exportDestinationGroup, SWT.BORDER ); exportDirectoryText.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) ); exportDirectoryText.addModifyListener( new ModifyListener() { public void modifyText( ModifyEvent e ) { dialogChanged(); } } ); exportDirectoryButton = new Button( exportDestinationGroup, SWT.PUSH ); exportDirectoryButton.setText( Messages.getString( "ExportProjectsWizardPage.Browse" ) ); //$NON-NLS-1$ exportDirectoryButton.addSelectionListener( new SelectionAdapter() { public void widgetSelected( SelectionEvent e ) { chooseExportDirectory(); dialogChanged(); } } ); initFields(); setControl( composite ); } /** * Initializes the UI Fields. */ private void initFields() { // Filling the Schemas table List<Project> projects = new ArrayList<Project>(); projects.addAll( Activator.getDefault().getProjectsHandler().getProjects() ); Collections.sort( projects, new Comparator<Project>() { public int compare( Project o1, Project o2 ) { return o1.getName().compareToIgnoreCase( o2.getName() ); } } ); projectsTableViewer.setInput( projects ); // Setting the selected projects projectsTableViewer.setCheckedElements( selectedProjects ); displayErrorMessage( null ); setPageComplete( false ); } /** * This method is called when the exportMultipleFiles 'browse' button is selected. */ private void chooseExportDirectory() { DirectoryDialog dialog = new DirectoryDialog( PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell() ); dialog.setText( Messages.getString( "ExportProjectsWizardPage.ChooseFolder" ) ); //$NON-NLS-1$ dialog.setMessage( Messages.getString( "ExportProjectsWizardPage.SelectFolderToExportTo" ) ); //$NON-NLS-1$ if ( "".equals( exportDirectoryText.getText() ) ) //$NON-NLS-1$ { dialog.setFilterPath( Activator.getDefault().getPreferenceStore().getString( PluginConstants.FILE_DIALOG_EXPORT_PROJECTS ) ); } else { dialog.setFilterPath( exportDirectoryText.getText() ); } String selectedDirectory = dialog.open(); if ( selectedDirectory != null ) { exportDirectoryText.setText( selectedDirectory ); } } /** * This method is called when the user modifies something in the UI. */ private void dialogChanged() { // Schemas table if ( projectsTableViewer.getCheckedElements().length == 0 ) { displayErrorMessage( Messages.getString( "ExportProjectsWizardPage.ErrorNoSchemaSelected" ) ); //$NON-NLS-1$ return; } // Export Directory String directory = exportDirectoryText.getText(); if ( ( directory == null ) || ( directory.equals( "" ) ) ) //$NON-NLS-1$ { displayErrorMessage( Messages.getString( "ExportProjectsWizardPage.ErrorNoDirectorySelected" ) ); //$NON-NLS-1$ return; } else { File directoryFile = new File( directory ); if ( !directoryFile.exists() ) { displayErrorMessage( Messages.getString( "ExportProjectsWizardPage.SelectedDirectoryNotExists" ) ); //$NON-NLS-1$ return; } else if ( !directoryFile.isDirectory() ) { displayErrorMessage( Messages.getString( "ExportProjectsWizardPage.SelectedDirectoryNotDirectory" ) ); //$NON-NLS-1$ return; } else if ( !directoryFile.canWrite() ) { displayErrorMessage( Messages.getString( "ExportProjectsWizardPage.SelectedDirectoryNotWritable" ) ); //$NON-NLS-1$ return; } } displayErrorMessage( null ); } /** * Gets the selected projects. * * @return * the selected projects */ public Project[] getSelectedProjects() { Object[] selectedProjects = projectsTableViewer.getCheckedElements(); List<Project> schemas = new ArrayList<Project>(); for ( Object project : selectedProjects ) { schemas.add( ( Project ) project ); } return schemas.toArray( new Project[0] ); } /** * Sets the selected projects. * * @param projects * the projects */ public void setSelectedProjects( Project[] projects ) { selectedProjects = projects; } /** * Gets the export directory. * * @return * the export directory */ public String getExportDirectory() { return exportDirectoryText.getText(); } /** * Saves the dialog settings. */ public void saveDialogSettings() { Activator.getDefault().getPreferenceStore().putValue( PluginConstants.FILE_DIALOG_EXPORT_PROJECTS, exportDirectoryText.getText() ); } }
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/wizards/ExportSchemasForADSWizardPage.java
plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/wizards/ExportSchemasForADSWizardPage.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.wizards; import java.io.File; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.List; 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.eclipse.jface.viewers.ArrayContentProvider; import org.eclipse.jface.viewers.CheckStateChangedEvent; import org.eclipse.jface.viewers.CheckboxTableViewer; import org.eclipse.jface.viewers.ICheckStateListener; import org.eclipse.jface.viewers.LabelProvider; 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.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.DirectoryDialog; import org.eclipse.swt.widgets.FileDialog; import org.eclipse.swt.widgets.Group; import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Table; import org.eclipse.swt.widgets.Text; import org.eclipse.ui.PlatformUI; /** * This class represents the WizardPage of the ExportSchemasForADSWizard. * <p> * It is used to let the user enter the informations about the * schemas he wants to export and where to export. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class ExportSchemasForADSWizardPage extends AbstractWizardPage { /** The selected schemas */ private Schema[] selectedSchemas = new Schema[0]; /** The SchemaHandler */ private SchemaHandler schemaHandler; public static final int EXPORT_MULTIPLE_FILES = 0; public static final int EXPORT_SINGLE_FILE = 1; // UI Fields private CheckboxTableViewer schemasTableViewer; private Button schemasTableSelectAllButton; private Button schemasTableDeselectAllButton; private Button exportMultipleFilesRadio; private Label exportMultipleFilesLabel; private Text exportMultipleFilesText; private Button exportMultipleFilesButton; private Button exportSingleFileRadio; private Label exportSingleFileLabel; private Text exportSingleFileText; private Button exportSingleFileButton; /** * Creates a new instance of ExportSchemasAsXmlWizardPage. */ protected ExportSchemasForADSWizardPage() { super( "ExportSchemasForADSWizardPage" ); //$NON-NLS-1$ setTitle( Messages.getString( "ExportSchemasForADSWizardPage.ExportSchemas" ) ); //$NON-NLS-1$ setDescription( Messages.getString( "ExportSchemasForADSWizardPage.PleaseSelectSchemasToExport" ) ); //$NON-NLS-1$ setImageDescriptor( Activator.getDefault().getImageDescriptor( PluginConstants.IMG_SCHEMAS_EXPORT_FOR_ADS_WIZARD ) ); schemaHandler = Activator.getDefault().getSchemaHandler(); } /** * {@inheritDoc} */ public void createControl( Composite parent ) { Composite composite = new Composite( parent, SWT.NULL ); GridLayout layout = new GridLayout(); composite.setLayout( layout ); // Schemas Group Group schemasGroup = new Group( composite, SWT.NONE ); schemasGroup.setText( Messages.getString( "ExportSchemasForADSWizardPage.Schemas" ) ); //$NON-NLS-1$ schemasGroup.setLayout( new GridLayout( 2, false ) ); schemasGroup.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) ); // Schemas TableViewer Label schemasLabel = new Label( schemasGroup, SWT.NONE ); schemasLabel.setText( Messages.getString( "ExportSchemasForADSWizardPage.SelectSchemaToExport" ) ); //$NON-NLS-1$ schemasLabel.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false, 2, 1 ) ); schemasTableViewer = new CheckboxTableViewer( new Table( schemasGroup, SWT.BORDER | SWT.CHECK | SWT.FULL_SELECTION ) ); GridData schemasTableViewerGridData = new GridData( SWT.FILL, SWT.NONE, true, false, 1, 2 ); schemasTableViewerGridData.heightHint = 125; schemasTableViewer.getTable().setLayoutData( schemasTableViewerGridData ); schemasTableViewer.setContentProvider( new ArrayContentProvider() ); schemasTableViewer.setLabelProvider( new LabelProvider() { public String getText( Object element ) { if ( element instanceof Schema ) { return ( ( Schema ) element ).getSchemaName(); } // Default return super.getText( element ); } public Image getImage( Object element ) { if ( element instanceof Schema ) { return Activator.getDefault().getImage( PluginConstants.IMG_SCHEMA ); } // Default return super.getImage( element ); } } ); schemasTableViewer.addCheckStateListener( new ICheckStateListener() { /** * Notifies of a change to the checked state of an element. * * @param event * event object describing the change */ public void checkStateChanged( CheckStateChangedEvent event ) { dialogChanged(); } } ); schemasTableSelectAllButton = new Button( schemasGroup, SWT.PUSH ); schemasTableSelectAllButton.setText( Messages.getString( "ExportSchemasForADSWizardPage.SelectAll" ) ); //$NON-NLS-1$ schemasTableSelectAllButton.setLayoutData( new GridData( SWT.FILL, SWT.BEGINNING, false, false ) ); schemasTableSelectAllButton.addSelectionListener( new SelectionAdapter() { public void widgetSelected( SelectionEvent e ) { schemasTableViewer.setAllChecked( true ); dialogChanged(); } } ); schemasTableDeselectAllButton = new Button( schemasGroup, SWT.PUSH ); schemasTableDeselectAllButton.setText( Messages.getString( "ExportSchemasForADSWizardPage.DeselectAll" ) ); //$NON-NLS-1$ schemasTableDeselectAllButton.setLayoutData( new GridData( SWT.FILL, SWT.BEGINNING, false, false ) ); schemasTableDeselectAllButton.addSelectionListener( new SelectionAdapter() { public void widgetSelected( SelectionEvent e ) { schemasTableViewer.setAllChecked( false ); dialogChanged(); } } ); // Export Destination Group Group exportDestinationGroup = new Group( composite, SWT.NULL ); exportDestinationGroup.setText( Messages.getString( "ExportSchemasForADSWizardPage.ExportDestination" ) ); //$NON-NLS-1$ exportDestinationGroup.setLayout( new GridLayout( 4, false ) ); exportDestinationGroup.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) ); // Export Multiple Files exportMultipleFilesRadio = new Button( exportDestinationGroup, SWT.RADIO ); exportMultipleFilesRadio.setText( Messages .getString( "ExportSchemasForADSWizardPage.ExportSchemaAsSeparateFiles" ) ); //$NON-NLS-1$ exportMultipleFilesRadio.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false, 4, 1 ) ); exportMultipleFilesRadio.addSelectionListener( new SelectionAdapter() { public void widgetSelected( SelectionEvent e ) { exportMultipleFilesSelected(); dialogChanged(); } } ); Label exportMultipleFilesFiller = new Label( exportDestinationGroup, SWT.NONE ); exportMultipleFilesFiller.setText( " " ); //$NON-NLS-1$ exportMultipleFilesLabel = new Label( exportDestinationGroup, SWT.NONE ); exportMultipleFilesLabel.setText( Messages.getString( "ExportSchemasForADSWizardPage.Directory" ) ); //$NON-NLS-1$ exportMultipleFilesText = new Text( exportDestinationGroup, SWT.BORDER ); exportMultipleFilesText.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) ); exportMultipleFilesText.addModifyListener( new ModifyListener() { public void modifyText( ModifyEvent e ) { dialogChanged(); } } ); exportMultipleFilesButton = new Button( exportDestinationGroup, SWT.PUSH ); exportMultipleFilesButton.setText( Messages.getString( "ExportSchemasForADSWizardPage.Browse" ) ); //$NON-NLS-1$ exportMultipleFilesButton.addSelectionListener( new SelectionAdapter() { public void widgetSelected( SelectionEvent e ) { chooseExportDirectory(); dialogChanged(); } } ); // Export Single File exportSingleFileRadio = new Button( exportDestinationGroup, SWT.RADIO ); exportSingleFileRadio.setText( Messages.getString( "ExportSchemasForADSWizardPage.ExportSchemaAsSingleFile" ) ); //$NON-NLS-1$ exportSingleFileRadio.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false, 4, 1 ) ); exportSingleFileRadio.addSelectionListener( new SelectionAdapter() { public void widgetSelected( SelectionEvent e ) { exportSingleFileSelected(); dialogChanged(); } } ); Label exportSingleFileFiller = new Label( exportDestinationGroup, SWT.NONE ); exportSingleFileFiller.setText( " " ); //$NON-NLS-1$ exportSingleFileLabel = new Label( exportDestinationGroup, SWT.NONE ); exportSingleFileLabel.setText( Messages.getString( "ExportSchemasForADSWizardPage.ExportFile" ) ); //$NON-NLS-1$ exportSingleFileText = new Text( exportDestinationGroup, SWT.BORDER ); exportSingleFileText.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) ); exportSingleFileText.addModifyListener( new ModifyListener() { public void modifyText( ModifyEvent e ) { dialogChanged(); } } ); exportSingleFileButton = new Button( exportDestinationGroup, SWT.PUSH ); exportSingleFileButton.setText( Messages.getString( "ExportSchemasForADSWizardPage.Browse" ) ); //$NON-NLS-1$ exportSingleFileButton.addSelectionListener( new SelectionAdapter() { /** * {@inheritDoc} */ public void widgetSelected( SelectionEvent e ) { chooseExportFile(); dialogChanged(); } } ); initFields(); dialogChanged(); setControl( composite ); } /** * Initializes the UI Fields. */ private void initFields() { // Filling the Schemas table if ( schemaHandler != null ) { List<Schema> schemas = new ArrayList<Schema>(); schemas.addAll( schemaHandler.getSchemas() ); Collections.sort( schemas, new Comparator<Schema>() { public int compare( Schema o1, Schema o2 ) { return o1.getSchemaName().compareToIgnoreCase( o2.getSchemaName() ); } } ); schemasTableViewer.setInput( schemas ); // Setting the selected schemas schemasTableViewer.setCheckedElements( selectedSchemas ); } // Selecting the Multiple Files choice exportMultipleFilesSelected(); displayErrorMessage( null ); setPageComplete( false ); } /** * This method is called when the exportMultipleFiles radio button is selected. */ private void exportMultipleFilesSelected() { exportMultipleFilesRadio.setSelection( true ); exportMultipleFilesLabel.setEnabled( true ); exportMultipleFilesText.setEnabled( true ); exportMultipleFilesButton.setEnabled( true ); exportSingleFileRadio.setSelection( false ); exportSingleFileLabel.setEnabled( false ); exportSingleFileText.setEnabled( false ); exportSingleFileButton.setEnabled( false ); } /** * This method is called when the exportSingleFile radio button is selected. */ private void exportSingleFileSelected() { exportMultipleFilesRadio.setSelection( false ); exportMultipleFilesLabel.setEnabled( false ); exportMultipleFilesText.setEnabled( false ); exportMultipleFilesButton.setEnabled( false ); exportSingleFileRadio.setSelection( true ); exportSingleFileLabel.setEnabled( true ); exportSingleFileText.setEnabled( true ); exportSingleFileButton.setEnabled( true ); } /** * This method is called when the exportMultipleFiles 'browse' button is selected. */ private void chooseExportDirectory() { DirectoryDialog dialog = new DirectoryDialog( PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell() ); dialog.setText( Messages.getString( "ExportSchemasForADSWizardPage.ChooseFolder" ) ); //$NON-NLS-1$ dialog.setMessage( Messages.getString( "ExportSchemasForADSWizardPage.SelectFolderToExportTo" ) ); //$NON-NLS-1$ if ( "".equals( exportMultipleFilesText.getText() ) ) //$NON-NLS-1$ { dialog.setFilterPath( Activator.getDefault().getPreferenceStore().getString( PluginConstants.FILE_DIALOG_EXPORT_SCHEMAS_APACHE_DS ) ); } else { dialog.setFilterPath( exportMultipleFilesText.getText() ); } String selectedDirectory = dialog.open(); if ( selectedDirectory != null ) { exportMultipleFilesText.setText( selectedDirectory ); } } /** * This method is called when the exportSingleFile 'browse' button is selected. */ private void chooseExportFile() { FileDialog dialog = new FileDialog( PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), SWT.SAVE ); dialog.setText( Messages.getString( "ExportSchemasForADSWizardPage.SelectFile" ) ); //$NON-NLS-1$ dialog.setFilterExtensions( new String[] { "*.ldif", "*" } ); //$NON-NLS-1$ //$NON-NLS-2$ dialog .setFilterNames( new String[] { Messages.getString( "ExportSchemasForADSWizardPage.LDIFFiles" ), Messages.getString( "ExportSchemasForADSWizardPage.AllFiles" ) } ); //$NON-NLS-1$ //$NON-NLS-2$ if ( "".equals( exportSingleFileText.getText() ) ) //$NON-NLS-1$ { dialog.setFilterPath( Activator.getDefault().getPreferenceStore().getString( PluginConstants.FILE_DIALOG_EXPORT_SCHEMAS_APACHE_DS ) ); } else { dialog.setFilterPath( exportSingleFileText.getText() ); } String selectedFile = dialog.open(); if ( selectedFile != null ) { exportSingleFileText.setText( selectedFile ); } } /** * This method is called when the user modifies something in the UI. */ private void dialogChanged() { // Checking if a Schema Project is open if ( schemaHandler == null ) { displayErrorMessage( Messages.getString( "ExportSchemasForADSWizardPage.ErrorNoSchemaProjectOpen" ) ); //$NON-NLS-1$ return; } // Schemas table if ( schemasTableViewer.getCheckedElements().length == 0 ) { displayErrorMessage( Messages.getString( "ExportSchemasForADSWizardPage.ErrorNoSchemaSelected" ) ); //$NON-NLS-1$ return; } // Export option if ( exportMultipleFilesRadio.getSelection() ) { String directory = exportMultipleFilesText.getText(); if ( ( directory == null ) || ( directory.equals( "" ) ) ) //$NON-NLS-1$ { displayErrorMessage( Messages.getString( "ExportSchemasForADSWizardPage.ErrorNoDirectorySelected" ) ); //$NON-NLS-1$ return; } else { File directoryFile = new File( directory ); if ( !directoryFile.exists() ) { displayErrorMessage( Messages .getString( "ExportSchemasForADSWizardPage.ErrorSelectedDirectoryNotExists" ) ); //$NON-NLS-1$ return; } else if ( !directoryFile.isDirectory() ) { displayErrorMessage( Messages .getString( "ExportSchemasForADSWizardPage.ErrorSelectedDirectoryNotDirectory" ) ); //$NON-NLS-1$ return; } else if ( !directoryFile.canWrite() ) { displayErrorMessage( Messages .getString( "ExportSchemasForADSWizardPage.ErrorSelectedDirectoryNotWritable" ) ); //$NON-NLS-1$ return; } } } else if ( exportSingleFileRadio.getSelection() ) { String exportFile = exportSingleFileText.getText(); if ( ( exportFile == null ) || ( exportFile.equals( "" ) ) ) //$NON-NLS-1$ { displayErrorMessage( Messages.getString( "ExportSchemasForADSWizardPage.ErrorNoFileSelected" ) ); //$NON-NLS-1$ return; } else { File file = new File( exportFile ); if ( !file.getParentFile().canWrite() ) { displayErrorMessage( Messages .getString( "ExportSchemasForADSWizardPage.ErrorSelectedFileNotWritable" ) ); //$NON-NLS-1$ return; } } } displayErrorMessage( null ); } /** * Gets the selected schemas. * * @return * the selected schemas */ public Schema[] getSelectedSchemas() { Object[] selectedSchemas = schemasTableViewer.getCheckedElements(); List<Schema> schemas = new ArrayList<Schema>(); for ( Object schema : selectedSchemas ) { schemas.add( ( Schema ) schema ); } return schemas.toArray( new Schema[0] ); } /** * Sets the selected projects. * * @param schemas * the schemas */ public void setSelectedSchemas( Schema[] schemas ) { selectedSchemas = schemas; } /** * Gets the type of export. * <p> * Values can either EXPORT_MULTIPLE_FILES or EXPORT_SINGLE_FILE. * * @return * the type of export */ public int getExportType() { if ( exportMultipleFilesRadio.getSelection() ) { return EXPORT_MULTIPLE_FILES; } else if ( exportSingleFileRadio.getSelection() ) { return EXPORT_SINGLE_FILE; } // Default return EXPORT_MULTIPLE_FILES; } /** * Gets the export directory. * * @return * the export directory */ public String getExportDirectory() { return exportMultipleFilesText.getText(); } /** * Gets the export file. * * @return * the export file */ public String getExportFile() { return exportSingleFileText.getText(); } /** * Saves the dialog settings. */ public void saveDialogSettings() { if ( exportMultipleFilesRadio.getSelection() ) { Activator.getDefault().getPreferenceStore().putValue( PluginConstants.FILE_DIALOG_EXPORT_SCHEMAS_APACHE_DS, exportMultipleFilesText.getText() ); } else { Activator.getDefault().getPreferenceStore().putValue( PluginConstants.FILE_DIALOG_EXPORT_SCHEMAS_APACHE_DS, new File( exportSingleFileText.getText() ).getParent() ); } } }
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/wizards/NewAttributeTypeMatchingRulesWizardPage.java
plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/wizards/NewAttributeTypeMatchingRulesWizardPage.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.wizards; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; 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.PluginConstants; import org.apache.directory.studio.schemaeditor.controller.SchemaHandler; import org.eclipse.jface.viewers.ArrayContentProvider; import org.eclipse.jface.viewers.ComboViewer; import org.eclipse.jface.viewers.LabelProvider; import org.eclipse.jface.viewers.StructuredSelection; import org.eclipse.jface.wizard.WizardPage; 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.Combo; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Group; import org.eclipse.swt.widgets.Label; /** * This class represents the Matching Rules WizardPage of the NewAttributeTypeWizard. * <p> * It is used to let the user enter matching rules information about the * attribute type he wants to create (equality, ordering, substring). * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class NewAttributeTypeMatchingRulesWizardPage extends WizardPage { /** The SchemaHandler */ private SchemaHandler schemaHandler; /** The LabelProvider */ private LabelProvider labelProvider = new LabelProvider() { /** * {@inheritDoc} */ public String getText( Object element ) { if ( element instanceof MatchingRule ) { MatchingRule mr = ( MatchingRule ) element; String name = mr.getName(); if ( name != null ) { return NLS .bind( Messages.getString( "NewAttributeTypeMatchingRulesWizardPage.NameOID" ), new String[] { name, mr.getOid() } ); //$NON-NLS-1$ } else { return NLS .bind( Messages.getString( "NewAttributeTypeMatchingRulesWizardPage.NoneOID" ), new String[] { mr.getOid() } ); //$NON-NLS-1$ } } return super.getText( element ); } }; // UI fields private ComboViewer equalityComboViewer; private ComboViewer orderingComboViewer; private ComboViewer substringComboViewer; /** * Creates a new instance of NewAttributeTypeMatchingRulesWizardPage. */ public NewAttributeTypeMatchingRulesWizardPage() { super( "NewAttributeTypeMatchingRulesWizardPage" ); //$NON-NLS-1$ setTitle( Messages.getString( "NewAttributeTypeMatchingRulesWizardPage.MatchingRules" ) ); //$NON-NLS-1$ setDescription( Messages.getString( "NewAttributeTypeMatchingRulesWizardPage.PleaseSpecifiyMatchingRules" ) ); //$NON-NLS-1$ setImageDescriptor( Activator.getDefault().getImageDescriptor( PluginConstants.IMG_ATTRIBUTE_TYPE_NEW_WIZARD ) ); schemaHandler = Activator.getDefault().getSchemaHandler(); } /** * {@inheritDoc} */ public void createControl( Composite parent ) { Composite composite = new Composite( parent, SWT.NULL ); GridLayout layout = new GridLayout(); composite.setLayout( layout ); // Matching Rules Group Group matchingRulesGroup = new Group( composite, SWT.NONE ); matchingRulesGroup.setText( Messages.getString( "NewAttributeTypeMatchingRulesWizardPage.MatchingRules" ) ); //$NON-NLS-1$ matchingRulesGroup.setLayout( new GridLayout( 2, false ) ); matchingRulesGroup.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false, 3, 1 ) ); // Equality Label equalityLabel = new Label( matchingRulesGroup, SWT.NONE ); equalityLabel.setText( Messages.getString( "NewAttributeTypeMatchingRulesWizardPage.Equality" ) ); //$NON-NLS-1$ Combo equalityCombo = new Combo( matchingRulesGroup, SWT.READ_ONLY ); equalityCombo.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) ); equalityComboViewer = new ComboViewer( equalityCombo ); equalityComboViewer.setContentProvider( new ArrayContentProvider() ); equalityComboViewer.setLabelProvider( labelProvider ); // Ordering Label orderingLabel = new Label( matchingRulesGroup, SWT.NONE ); orderingLabel.setText( Messages.getString( "NewAttributeTypeMatchingRulesWizardPage.Ordering" ) ); //$NON-NLS-1$ Combo orderingCombo = new Combo( matchingRulesGroup, SWT.READ_ONLY ); orderingCombo.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) ); orderingComboViewer = new ComboViewer( orderingCombo ); orderingComboViewer.setContentProvider( new ArrayContentProvider() ); orderingComboViewer.setLabelProvider( labelProvider ); // Substring Label substringLabel = new Label( matchingRulesGroup, SWT.NONE ); substringLabel.setText( Messages.getString( "NewAttributeTypeMatchingRulesWizardPage.Substring" ) ); //$NON-NLS-1$ Combo substringCombo = new Combo( matchingRulesGroup, SWT.READ_ONLY ); substringCombo.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) ); substringComboViewer = new ComboViewer( substringCombo ); substringComboViewer.setContentProvider( new ArrayContentProvider() ); substringComboViewer.setLabelProvider( labelProvider ); initFields(); setControl( composite ); } /** * Initializes the UI fields. */ private void initFields() { if ( schemaHandler != null ) { // Getting the matching rules List<Object> matchingRules = new ArrayList<Object>( schemaHandler.getMatchingRules() ); // Adding the (None) matching rule String none = Messages.getString( "NewAttributeTypeMatchingRulesWizardPage.None" ); //$NON-NLS-1$ matchingRules.add( none ); // Sorting the matching rules Collections.sort( matchingRules, new Comparator<Object>() { public int compare( Object o1, Object o2 ) { if ( ( o1 instanceof MatchingRule ) && ( o2 instanceof MatchingRule ) ) { List<String> o1Names = ( ( MatchingRule ) o1 ).getNames(); List<String> o2Names = ( ( MatchingRule ) o2 ).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$ } } else if ( ( o1 instanceof String ) && ( o2 instanceof MatchingRule ) ) { return Integer.MIN_VALUE; } else if ( ( o1 instanceof MatchingRule ) && ( o2 instanceof String ) ) { return Integer.MAX_VALUE; } } // Default return o1.toString().compareToIgnoreCase( o2.toString() ); } } ); // Setting the input equalityComboViewer.setInput( matchingRules ); orderingComboViewer.setInput( matchingRules ); substringComboViewer.setInput( matchingRules ); // Selecting the None matching rules equalityComboViewer.setSelection( new StructuredSelection( none ) ); orderingComboViewer.setSelection( new StructuredSelection( none ) ); substringComboViewer.setSelection( new StructuredSelection( none ) ); } } /** * Gets the value of the equality matching rule. * * @return * the value of the equality matching rule */ public String getEqualityMatchingRuleValue() { Object selection = ( ( StructuredSelection ) equalityComboViewer.getSelection() ).getFirstElement(); if ( selection instanceof MatchingRule ) { MatchingRule mr = ( ( MatchingRule ) selection ); List<String> names = mr.getNames(); if ( ( names != null ) && ( names.size() > 0 ) ) { return mr.getName(); } else { return mr.getOid(); } } return null; } /** * Gets the value of the ordering matching rule. * * @return * the value of the ordering matching rule */ public String getOrderingMatchingRuleValue() { Object selection = ( ( StructuredSelection ) orderingComboViewer.getSelection() ).getFirstElement(); if ( selection instanceof MatchingRule ) { MatchingRule mr = ( ( MatchingRule ) selection ); List<String> names = mr.getNames(); if ( ( names != null ) && ( names.size() > 0 ) ) { return mr.getName(); } else { return mr.getOid(); } } return null; } /** * Gets the value of the substring matching rule. * * @return * the value of the substring matching rule */ public String getSubstringMatchingRuleValue() { Object selection = ( ( StructuredSelection ) substringComboViewer.getSelection() ).getFirstElement(); if ( selection instanceof MatchingRule ) { MatchingRule mr = ( ( MatchingRule ) selection ); List<String> names = mr.getNames(); if ( ( names != null ) && ( names.size() > 0 ) ) { return mr.getName(); } else { return mr.getOid(); } } 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/wizards/ExportSchemasForADSWizard.java
plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/wizards/ExportSchemasForADSWizard.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.wizards; import java.io.BufferedWriter; import java.io.FileWriter; import java.io.IOException; import java.lang.reflect.InvocationTargetException; import java.text.DateFormat; import java.util.ArrayList; import java.util.Date; import java.util.HashSet; import java.util.List; import java.util.Set; import org.apache.directory.api.ldap.model.constants.SchemaConstants; import org.apache.directory.api.ldap.model.exception.LdapException; import org.apache.directory.api.ldap.model.name.Rdn; 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.SchemaObjectSorter; import org.apache.directory.api.ldap.schema.converter.AttributeTypeHolder; import org.apache.directory.api.ldap.schema.converter.ObjectClassHolder; import org.apache.directory.api.util.Strings; import org.apache.directory.studio.schemaeditor.Activator; import org.apache.directory.studio.schemaeditor.PluginUtils; import org.apache.directory.studio.schemaeditor.controller.SchemaHandler; import org.apache.directory.studio.schemaeditor.model.Schema; import org.apache.directory.studio.schemaeditor.view.ViewUtils; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.jface.operation.IRunnableWithProgress; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jface.wizard.Wizard; import org.eclipse.osgi.util.NLS; import org.eclipse.ui.IExportWizard; import org.eclipse.ui.IWorkbench; /** * This class represents the wizard to export schemas for ApacheDS. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class ExportSchemasForADSWizard extends Wizard implements IExportWizard { /** The selected schemas */ private Schema[] selectedSchemas = new Schema[0]; // The pages of the wizard private ExportSchemasForADSWizardPage page; /** * {@inheritDoc} */ public void addPages() { // Creating pages page = new ExportSchemasForADSWizardPage(); page.setSelectedSchemas( selectedSchemas ); // Adding pages addPage( page ); } /** * {@inheritDoc} */ public boolean performFinish() { // Saving the dialog settings page.saveDialogSettings(); // Getting the schemas to be exported and where to export them final Schema[] selectedSchemas = page.getSelectedSchemas(); int exportType = page.getExportType(); if ( exportType == ExportSchemasAsXmlWizardPage.EXPORT_MULTIPLE_FILES ) { final String exportDirectory = page.getExportDirectory(); try { getContainer().run( false, true, new IRunnableWithProgress() { public void run( IProgressMonitor monitor ) { monitor.beginTask( Messages.getString( "ExportSchemasForADSWizard.ExportingSchemas" ), selectedSchemas.length ); //$NON-NLS-1$ for ( Schema schema : selectedSchemas ) { monitor.subTask( schema.getSchemaName() ); StringBuffer sb = new StringBuffer(); DateFormat format = DateFormat.getDateTimeInstance( DateFormat.LONG, DateFormat.MEDIUM ); Date date = new Date(); sb .append( NLS .bind( Messages.getString( "ExportSchemasForADSWizard.GeneratedByApacheComment" ), new String[] { format.format( date ) } ) ); //$NON-NLS-1$ try { toLdif( schema, sb ); BufferedWriter buffWriter = new BufferedWriter( new FileWriter( exportDirectory + "/" //$NON-NLS-1$ + schema.getSchemaName() + ".ldif" ) ); //$NON-NLS-1$ buffWriter.write( sb.toString() ); buffWriter.close(); } catch ( Exception e ) { PluginUtils .logError( NLS .bind( Messages.getString( "ExportSchemasForADSWizard.ErrorSavingSchema" ), new String[] { schema.getSchemaName() } ), e ); //$NON-NLS-1$ ViewUtils .displayErrorMessageDialog( Messages.getString( "ExportSchemasForADSWizard.Error" ), NLS.bind( Messages.getString( "ExportSchemasForADSWizard.ErrorSavingSchema" ), new String[] { schema.getSchemaName() } ) ); //$NON-NLS-1$ //$NON-NLS-2$ } monitor.worked( 1 ); } monitor.done(); } } ); } catch ( InvocationTargetException e ) { // Nothing to do (it will never occur) } catch ( InterruptedException e ) { // Nothing to do. } } else if ( exportType == ExportSchemasAsXmlWizardPage.EXPORT_SINGLE_FILE ) { final String exportFile = page.getExportFile(); try { getContainer().run( false, true, new IRunnableWithProgress() { public void run( IProgressMonitor monitor ) { monitor.beginTask( Messages.getString( "ExportSchemasForADSWizard.ExportingSchemas" ), 1 ); //$NON-NLS-1$ StringBuffer sb = new StringBuffer(); DateFormat format = DateFormat.getDateTimeInstance( DateFormat.LONG, DateFormat.MEDIUM ); Date date = new Date(); sb .append( NLS .bind( Messages.getString( "ExportSchemasForADSWizard.GeneratedByApacheComment" ), new String[] { format.format( date ) } ) ); //$NON-NLS-1$ for ( Schema schema : selectedSchemas ) { try { toLdif( schema, sb ); } catch ( Exception e ) { PluginUtils .logError( NLS .bind( Messages.getString( "ExportSchemasForADSWizard.ErrorSavingSchema" ), new String[] { schema.getSchemaName() } ), e ); //$NON-NLS-1$ ViewUtils .displayErrorMessageDialog( Messages.getString( "ExportSchemasForADSWizard.Error" ), NLS.bind( Messages.getString( "ExportSchemasForADSWizard.ErrorSavingSchema" ), new String[] { schema.getSchemaName() } ) ); //$NON-NLS-1$ //$NON-NLS-2$ } } try { BufferedWriter buffWriter = new BufferedWriter( new FileWriter( exportFile ) ); buffWriter.write( sb.toString() ); buffWriter.close(); } catch ( IOException e ) { PluginUtils.logError( Messages.getString( "ExportSchemasForADSWizard.ErrorSavingSchemas" ), e ); //$NON-NLS-1$ ViewUtils .displayErrorMessageDialog( Messages.getString( "ExportSchemasForADSWizard.Error" ), Messages.getString( "ExportSchemasForADSWizard.ErrorSavingSchemas" ) ); //$NON-NLS-1$ //$NON-NLS-2$ } monitor.worked( 1 ); monitor.done(); } } ); } catch ( InvocationTargetException e ) { // Nothing to do (it will never occur) } catch ( InterruptedException e ) { // Nothing to do. } } return true; } /** * Converts the given schema as its LDIF for ApacheDS representation and stores it into the given StringBuffer. * * @param schema * the schema * @param sb * the StringBuffer * @throws LdapException */ private void toLdif( Schema schema, StringBuffer sb ) throws LdapException { sb .append( NLS .bind( Messages.getString( "ExportSchemasForADSWizard.SchemaComment" ), new String[] { schema.getSchemaName().toUpperCase() } ) ); //$NON-NLS-1$ sb.append( "dn: cn=" + Rdn.escapeValue( schema.getSchemaName() ) + ", ou=schema\n" ); //$NON-NLS-1$ //$NON-NLS-2$ sb.append( "objectclass: metaSchema\n" ); //$NON-NLS-1$ sb.append( "objectclass: top\n" ); //$NON-NLS-1$ sb.append( "cn: " + schema.getSchemaName() + "\n" ); //$NON-NLS-1$ //$NON-NLS-2$ String[] schemaDependencies = getSchemaDependencies( schema ); for ( String schemaName : schemaDependencies ) { sb.append( "m-dependencies: " + schemaName + "\n" ); //$NON-NLS-1$ //$NON-NLS-2$ } sb.append( "\n" ); //$NON-NLS-1$ // Generation the Attribute Types Node sb.append( "dn: " + SchemaConstants.ATTRIBUTE_TYPES_PATH + ", cn=" + Rdn.escapeValue( schema.getSchemaName() ) + ", ou=schema\n" ); //$NON-NLS-1$ //$NON-NLS-2$ sb.append( "objectclass: organizationalUnit\n" ); //$NON-NLS-1$ sb.append( "objectclass: top\n" ); //$NON-NLS-1$ sb.append( "ou: attributetypes\n" ); //$NON-NLS-1$ sb.append( "\n" ); //$NON-NLS-1$ // Generating LDIF for Attributes Types for ( AttributeType at : schema.getAttributeTypes() ) { AttributeTypeHolder holder = new AttributeTypeHolder( at.getOid() ); holder.setCollective( at.isCollective() ); holder.setDescription( at.getDescription() ); holder.setEquality( at.getEqualityOid() ); List<String> names = new ArrayList<String>(); for ( String name : at.getNames() ) { names.add( name ); } holder.setNames( names ); holder.setNoUserModification( !at.isUserModifiable() ); holder.setObsolete( at.isObsolete() ); holder.setOrdering( at.getOrderingOid() ); holder.setSingleValue( at.isSingleValued() ); holder.setSubstr( at.getSubstringOid() ); holder.setSuperior( at.getSuperiorOid() ); holder.setSyntax( at.getSyntaxOid() ); if ( at.getSyntaxLength() > 0 ) { holder.setOidLen( at.getSyntaxLength() ); } holder.setUsage( at.getUsage() ); sb.append( holder.toLdif( schema.getSchemaName() ) + "\n" ); //$NON-NLS-1$ } // Generation the Comparators Node sb.append( "dn: " + SchemaConstants.COMPARATORS_PATH + ", cn=" + Rdn.escapeValue( schema.getSchemaName() ) + ", ou=schema\n" ); //$NON-NLS-1$ //$NON-NLS-2$ sb.append( "objectclass: organizationalUnit\n" ); //$NON-NLS-1$ sb.append( "objectclass: top\n" ); //$NON-NLS-1$ sb.append( "ou: comparators\n" ); //$NON-NLS-1$ sb.append( "\n" ); //$NON-NLS-1$ // Generation the DIT Content Rules Node sb.append( "dn: " + SchemaConstants.DIT_CONTENT_RULES_PATH + ", cn=" + Rdn.escapeValue( schema.getSchemaName() ) + ", ou=schema\n" ); //$NON-NLS-1$ //$NON-NLS-2$ sb.append( "objectclass: organizationalUnit\n" ); //$NON-NLS-1$ sb.append( "objectclass: top\n" ); //$NON-NLS-1$ sb.append( "ou: ditcontentrules\n" ); //$NON-NLS-1$ sb.append( "\n" ); //$NON-NLS-1$ // Generation the DIT Structure RulesNode sb.append( "dn: " + SchemaConstants.DIT_STRUCTURE_RULES_PATH + ", cn=" + Rdn.escapeValue( schema.getSchemaName() ) + ", ou=schema\n" ); //$NON-NLS-1$ //$NON-NLS-2$ sb.append( "objectclass: organizationalUnit\n" ); //$NON-NLS-1$ sb.append( "objectclass: top\n" ); //$NON-NLS-1$ sb.append( "ou: ditstructurerules\n" ); //$NON-NLS-1$ sb.append( "\n" ); //$NON-NLS-1$ // Generation the Matching Rules Node sb.append( "dn: " + SchemaConstants.MATCHING_RULES_PATH + ", cn=" + Rdn.escapeValue( schema.getSchemaName() ) + ", ou=schema\n" ); //$NON-NLS-1$ //$NON-NLS-2$ sb.append( "objectclass: organizationalUnit\n" ); //$NON-NLS-1$ sb.append( "objectclass: top\n" ); //$NON-NLS-1$ sb.append( "ou: matchingrules\n" ); //$NON-NLS-1$ sb.append( "\n" ); //$NON-NLS-1$ // Generation the Matching Rule Use Node sb.append( "dn: " + SchemaConstants.MATCHING_RULE_USE_PATH + ", cn=" + Rdn.escapeValue( schema.getSchemaName() ) + ", ou=schema\n" ); //$NON-NLS-1$ //$NON-NLS-2$ sb.append( "objectclass: organizationalUnit\n" ); //$NON-NLS-1$ sb.append( "objectclass: top\n" ); //$NON-NLS-1$ sb.append( "ou: matchingruleuse\n" ); //$NON-NLS-1$ sb.append( "\n" ); //$NON-NLS-1$ // Generation the Name Forms Node sb.append( "dn: " + SchemaConstants.NAME_FORMS_PATH + ", cn=" + Rdn.escapeValue( schema.getSchemaName() ) + ", ou=schema\n" ); //$NON-NLS-1$ //$NON-NLS-2$ sb.append( "objectclass: organizationalUnit\n" ); //$NON-NLS-1$ sb.append( "objectclass: top\n" ); //$NON-NLS-1$ sb.append( "ou: nameforms\n" ); //$NON-NLS-1$ sb.append( "\n" ); //$NON-NLS-1$ // Generation the Normalizers Node sb.append( "dn: " + SchemaConstants.NORMALIZERS_PATH + ", cn=" + Rdn.escapeValue( schema.getSchemaName() ) + ", ou=schema\n" ); //$NON-NLS-1$ //$NON-NLS-2$ sb.append( "objectclass: organizationalUnit\n" ); //$NON-NLS-1$ sb.append( "objectclass: top\n" ); //$NON-NLS-1$ sb.append( "ou: normalizers\n" ); //$NON-NLS-1$ sb.append( "\n" ); //$NON-NLS-1$ // Generation the Object Classes Node sb.append( "dn: " + SchemaConstants.OBJECT_CLASSES_PATH + ", cn=" + Rdn.escapeValue( schema.getSchemaName() ) + ", ou=schema\n" ); //$NON-NLS-1$ //$NON-NLS-2$ sb.append( "objectclass: organizationalUnit\n" ); //$NON-NLS-1$ sb.append( "objectclass: top\n" ); //$NON-NLS-1$ sb.append( "ou: objectClasses\n" ); //$NON-NLS-1$ sb.append( "\n" ); //$NON-NLS-1$ // Generating LDIF for Object Classes Iterable<ObjectClass> sortedObjectClasses = SchemaObjectSorter.sortObjectClasses( schema.getObjectClasses() ); for ( ObjectClass oc : sortedObjectClasses ) { ObjectClassHolder holder = new ObjectClassHolder( oc.getOid() ); holder.setClassType( oc.getType() ); holder.setDescription( oc.getDescription() ); List<String> mayList = new ArrayList<String>(); for ( String may : oc.getMayAttributeTypeOids() ) { mayList.add( may ); } holder.setMay( mayList ); List<String> mustList = new ArrayList<String>(); for ( String must : oc.getMustAttributeTypeOids() ) { mustList.add( must ); } holder.setMust( mustList ); List<String> names = new ArrayList<String>(); for ( String name : oc.getNames() ) { names.add( name ); } holder.setNames( names ); List<String> superiorList = new ArrayList<String>(); for ( String superior : oc.getSuperiorOids() ) { superiorList.add( superior ); } holder.setSuperiors( superiorList ); holder.setObsolete( oc.isObsolete() ); sb.append( holder.toLdif( schema.getSchemaName() ) + "\n" ); //$NON-NLS-1$ } // Generation the Syntax Checkers Node sb.append( "dn: " + SchemaConstants.SYNTAX_CHECKERS_PATH + ", cn=" + Rdn.escapeValue( schema.getSchemaName() ) + ", ou=schema\n" ); //$NON-NLS-1$ //$NON-NLS-2$ sb.append( "objectclass: organizationalUnit\n" ); //$NON-NLS-1$ sb.append( "objectclass: top\n" ); //$NON-NLS-1$ sb.append( "ou: syntaxcheckers\n" ); //$NON-NLS-1$ sb.append( "\n" ); //$NON-NLS-1$ // Generation the Syntaxes Node sb.append( "dn: " + SchemaConstants.SYNTAXES_PATH + ", cn=" + Rdn.escapeValue( schema.getSchemaName() ) + ", ou=schema\n" ); //$NON-NLS-1$ //$NON-NLS-2$ sb.append( "objectclass: organizationalUnit\n" ); //$NON-NLS-1$ sb.append( "objectclass: top\n" ); //$NON-NLS-1$ sb.append( "ou: syntaxes\n" ); //$NON-NLS-1$ sb.append( "\n" ); //$NON-NLS-1$ } /** * Gets the schema dependencies. * * @param schema * the schema * @return * an array containing the names of all the schemas which the given * schema depends on */ private String[] getSchemaDependencies( Schema schema ) { Set<String> schemaNames = new HashSet<String>(); SchemaHandler schemaHandler = Activator.getDefault().getSchemaHandler(); // Looping on Attribute Types for ( AttributeType at : schema.getAttributeTypes() ) { // Superior String supName = at.getSuperiorOid(); if ( supName != null ) { AttributeType sup = schemaHandler.getAttributeType( supName ); if ( sup != null ) { if ( !Strings.toLowerCase( schema.getSchemaName() ).equals( Strings.toLowerCase( sup.getSchemaName() ) ) ) { schemaNames.add( sup.getSchemaName() ); } } } } // Looping on Object Classes for ( ObjectClass oc : schema.getObjectClasses() ) { // Superiors List<String> supNames = oc.getSuperiorOids(); if ( supNames != null ) { for ( String supName : oc.getSuperiorOids() ) { ObjectClass sup = schemaHandler.getObjectClass( supName ); if ( sup != null ) { if ( !Strings.toLowerCase( schema.getSchemaName() ).equals( Strings.toLowerCase( sup.getSchemaName() ) ) ) { schemaNames.add( sup.getSchemaName() ); } } } } // Mays List<String> mayNames = oc.getMayAttributeTypeOids(); if ( mayNames != null ) { for ( String mayName : mayNames ) { AttributeType may = schemaHandler.getAttributeType( mayName ); if ( may != null ) { if ( !Strings.toLowerCase( schema.getSchemaName() ).equals( Strings.toLowerCase( may.getSchemaName() ) ) ) { schemaNames.add( may.getSchemaName() ); } } } } // Musts List<String> mustNames = oc.getMustAttributeTypeOids(); if ( mustNames != null ) { for ( String mustName : oc.getMustAttributeTypeOids() ) { AttributeType must = schemaHandler.getAttributeType( mustName ); if ( must != null ) { if ( !Strings.toLowerCase( schema.getSchemaName() ).equals( Strings.toLowerCase( must.getSchemaName() ) ) ) { schemaNames.add( must.getSchemaName() ); } } } } } return schemaNames.toArray( new String[0] ); } /** * {@inheritDoc} */ public void init( IWorkbench workbench, IStructuredSelection selection ) { setNeedsProgressMonitor( true ); } /** * Sets the selected projects. * * @param schemas * the schemas */ public void setSelectedSchemas( Schema[] schemas ) { selectedSchemas = schemas; } }
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/wizards/ImportSchemasFromXmlWizardPage.java
plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/wizards/ImportSchemasFromXmlWizardPage.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.wizards; import java.io.File; import java.util.ArrayList; import java.util.List; import org.apache.directory.studio.schemaeditor.Activator; import org.apache.directory.studio.schemaeditor.PluginConstants; import org.eclipse.jface.viewers.ArrayContentProvider; import org.eclipse.jface.viewers.CheckStateChangedEvent; import org.eclipse.jface.viewers.CheckboxTableViewer; import org.eclipse.jface.viewers.ICheckStateListener; import org.eclipse.jface.viewers.LabelProvider; 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.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.DirectoryDialog; import org.eclipse.swt.widgets.Group; import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Table; import org.eclipse.swt.widgets.Text; import org.eclipse.ui.PlatformUI; /** * This class represents the WizardPage of the ImportSchemasFromOpenLdapWizard. * <p> * It is used to let the user enter the informations about the * schemas he wants to import. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class ImportSchemasFromXmlWizardPage extends AbstractWizardPage { // UI Fields private Text fromDirectoryText; private Button fromDirectoryButton; private CheckboxTableViewer schemaFilesTableViewer; private Button schemaFilesTableSelectAllButton; private Button schemaFilesTableDeselectAllButton; /** * Creates a new instance of ImportSchemasFromOpenLdapWizardPage. */ protected ImportSchemasFromXmlWizardPage() { super( "ImportSchemasFromXmlWizardPage" ); //$NON-NLS-1$ setTitle( Messages.getString( "ImportSchemasFromXmlWizardPage.ImportSchemasFromXML" ) ); //$NON-NLS-1$ setDescription( Messages.getString( "ImportSchemasFromXmlWizardPage.SelectXMLSchemaToImport" ) ); //$NON-NLS-1$ setImageDescriptor( Activator.getDefault().getImageDescriptor( PluginConstants.IMG_SCHEMAS_IMPORT_WIZARD ) ); } /** * {@inheritDoc} */ public void createControl( Composite parent ) { Composite composite = new Composite( parent, SWT.NULL ); GridLayout layout = new GridLayout(); composite.setLayout( layout ); // From Directory Group Group fromDirectoryGroup = new Group( composite, SWT.NONE ); fromDirectoryGroup.setText( Messages.getString( "ImportSchemasFromXmlWizardPage.FromDirectory" ) ); //$NON-NLS-1$ fromDirectoryGroup.setLayout( new GridLayout( 3, false ) ); fromDirectoryGroup.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) ); // From Directory Label fromDirectoryLabel = new Label( fromDirectoryGroup, SWT.NONE ); fromDirectoryLabel.setText( Messages.getString( "ImportSchemasFromXmlWizardPage.FromDirectoryColon" ) ); //$NON-NLS-1$ fromDirectoryText = new Text( fromDirectoryGroup, SWT.BORDER ); fromDirectoryText.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) ); fromDirectoryText.addModifyListener( new ModifyListener() { public void modifyText( ModifyEvent e ) { dialogChanged(); } } ); fromDirectoryButton = new Button( fromDirectoryGroup, SWT.PUSH ); fromDirectoryButton.setText( Messages.getString( "ImportSchemasFromXmlWizardPage.Browse" ) ); //$NON-NLS-1$ fromDirectoryButton.addSelectionListener( new SelectionAdapter() { public void widgetSelected( SelectionEvent e ) { chooseFromDirectory(); } } ); // Schema Files Group Group schemaFilesGroup = new Group( composite, SWT.NONE ); schemaFilesGroup.setText( Messages.getString( "ImportSchemasFromXmlWizardPage.SchemaFiles" ) ); //$NON-NLS-1$ schemaFilesGroup.setLayout( new GridLayout( 2, false ) ); schemaFilesGroup.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) ); // Schema Files schemaFilesTableViewer = new CheckboxTableViewer( new Table( schemaFilesGroup, SWT.BORDER | SWT.CHECK | SWT.FULL_SELECTION ) ); GridData schemasTableViewerGridData = new GridData( SWT.FILL, SWT.NONE, true, false, 1, 2 ); schemasTableViewerGridData.heightHint = 125; schemaFilesTableViewer.getTable().setLayoutData( schemasTableViewerGridData ); schemaFilesTableViewer.setContentProvider( new ArrayContentProvider() ); schemaFilesTableViewer.setLabelProvider( new LabelProvider() { public String getText( Object element ) { if ( element instanceof File ) { return ( ( File ) element ).getName(); } // Default return super.getText( element ); } public Image getImage( Object element ) { if ( element instanceof File ) { return Activator.getDefault().getImage( PluginConstants.IMG_SCHEMA ); } // Default return super.getImage( element ); } } ); schemaFilesTableViewer.addCheckStateListener( new ICheckStateListener() { /** * Notifies of a change to the checked state of an element. * * @param event * event object describing the change */ public void checkStateChanged( CheckStateChangedEvent event ) { dialogChanged(); } } ); schemaFilesTableSelectAllButton = new Button( schemaFilesGroup, SWT.PUSH ); schemaFilesTableSelectAllButton.setText( Messages.getString( "ImportSchemasFromXmlWizardPage.SelectAll" ) ); //$NON-NLS-1$ schemaFilesTableSelectAllButton.setLayoutData( new GridData( SWT.FILL, SWT.BEGINNING, false, false ) ); schemaFilesTableSelectAllButton.addSelectionListener( new SelectionAdapter() { public void widgetSelected( SelectionEvent e ) { schemaFilesTableViewer.setAllChecked( true ); dialogChanged(); } } ); schemaFilesTableDeselectAllButton = new Button( schemaFilesGroup, SWT.PUSH ); schemaFilesTableDeselectAllButton.setText( Messages.getString( "ImportSchemasFromXmlWizardPage.DeselectAll" ) ); //$NON-NLS-1$ schemaFilesTableDeselectAllButton.setLayoutData( new GridData( SWT.FILL, SWT.BEGINNING, false, false ) ); schemaFilesTableDeselectAllButton.addSelectionListener( new SelectionAdapter() { public void widgetSelected( SelectionEvent e ) { schemaFilesTableViewer.setAllChecked( false ); dialogChanged(); } } ); initFields(); dialogChanged(); setControl( composite ); } /** * Initializes the UI Fields. */ private void initFields() { displayErrorMessage( null ); setPageComplete( false ); } /** * This method is called when the exportMultipleFiles 'browse' button is selected. */ private void chooseFromDirectory() { DirectoryDialog dialog = new DirectoryDialog( PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell() ); dialog.setText( Messages.getString( "ImportSchemasFromXmlWizardPage.ChooseFolder" ) ); //$NON-NLS-1$ dialog.setMessage( Messages.getString( "ImportSchemasFromXmlWizardPage.SelectFolderToImportFrom" ) ); //$NON-NLS-1$ if ( "".equals( fromDirectoryText.getText() ) ) //$NON-NLS-1$ { dialog.setFilterPath( Activator.getDefault().getPreferenceStore().getString( PluginConstants.FILE_DIALOG_IMPORT_SCHEMAS_XML ) ); } else { dialog.setFilterPath( fromDirectoryText.getText() ); } String selectedDirectory = dialog.open(); if ( selectedDirectory != null ) { fromDirectoryText.setText( selectedDirectory ); fillInSchemaFilesTable( selectedDirectory ); } } /** * Fills in the SchemaFilesTable with the schema files found in the given path. * * @param path * the path to search schema files in */ private void fillInSchemaFilesTable( String path ) { List<File> schemaFiles = new ArrayList<File>(); File selectedDirectory = new File( path ); if ( selectedDirectory.exists() ) { for ( File file : selectedDirectory.listFiles() ) { String fileName = file.getName(); if ( fileName.endsWith( ".xml" ) ) //$NON-NLS-1$ { schemaFiles.add( file ); } } } schemaFilesTableViewer.setInput( schemaFiles ); } /** * This method is called when the user modifies something in the UI. */ private void dialogChanged() { // Checking if a Schema Project is open if ( Activator.getDefault().getSchemaHandler() == null ) { displayErrorMessage( Messages.getString( "ImportSchemasFromXmlWizardPage.ErrorNoSchemaProjectOpen" ) ); //$NON-NLS-1$ return; } // Export Directory String directory = fromDirectoryText.getText(); if ( ( directory == null ) || ( directory.equals( "" ) ) ) //$NON-NLS-1$ { displayErrorMessage( Messages.getString( "ImportSchemasFromXmlWizardPage.ErrorNoDirectorySelected" ) ); //$NON-NLS-1$ return; } else { File directoryFile = new File( directory ); if ( !directoryFile.exists() ) { displayErrorMessage( Messages .getString( "ImportSchemasFromXmlWizardPage.ErrorSelectedDirectoryNotExists" ) ); //$NON-NLS-1$ return; } else if ( !directoryFile.isDirectory() ) { displayErrorMessage( Messages .getString( "ImportSchemasFromXmlWizardPage.ErrorSelectedDirectoryNotDirectory" ) ); //$NON-NLS-1$ return; } else if ( !directoryFile.canRead() ) { displayErrorMessage( Messages .getString( "ImportSchemasFromXmlWizardPage.ErrorSelectedDirectoryNotReadable" ) ); //$NON-NLS-1$ return; } } // Schemas table if ( schemaFilesTableViewer.getCheckedElements().length == 0 ) { displayErrorMessage( Messages.getString( "ImportSchemasFromXmlWizardPage.ErrorNoSchemaSelected" ) ); //$NON-NLS-1$ return; } displayErrorMessage( null ); } /** * Gets the selected schema files. * * @return * the selected schema files */ public File[] getSelectedSchemaFiles() { Object[] selectedSchemaFile = schemaFilesTableViewer.getCheckedElements(); List<File> schemaFiles = new ArrayList<File>(); for ( Object schemaFile : selectedSchemaFile ) { schemaFiles.add( ( File ) schemaFile ); } return schemaFiles.toArray( new File[0] ); } /** * Saves the dialog settings. */ public void saveDialogSettings() { Activator.getDefault().getPreferenceStore().putValue( PluginConstants.FILE_DIALOG_IMPORT_SCHEMAS_XML, fromDirectoryText.getText() ); } }
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/wizards/ExportSchemasAsOpenLdapWizard.java
plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/wizards/ExportSchemasAsOpenLdapWizard.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.wizards; import java.io.BufferedWriter; import java.io.FileWriter; import java.io.IOException; import java.lang.reflect.InvocationTargetException; import org.apache.directory.studio.schemaeditor.PluginUtils; import org.apache.directory.studio.schemaeditor.model.Schema; import org.apache.directory.studio.schemaeditor.model.io.OpenLdapSchemaFileExporter; import org.apache.directory.studio.schemaeditor.view.ViewUtils; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.jface.operation.IRunnableWithProgress; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jface.wizard.Wizard; import org.eclipse.osgi.util.NLS; import org.eclipse.ui.IExportWizard; import org.eclipse.ui.IWorkbench; /** * This class represents the wizard to export schemas as OpenLdap format. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class ExportSchemasAsOpenLdapWizard extends Wizard implements IExportWizard { /** The selected schemas */ private Schema[] selectedSchemas = new Schema[0]; // The pages of the wizard private ExportSchemasAsOpenLdapWizardPage page; /** * {@inheritDoc} */ public void addPages() { // Creating pages page = new ExportSchemasAsOpenLdapWizardPage(); page.setSelectedSchemas( selectedSchemas ); // Adding pages addPage( page ); } /** * {@inheritDoc} */ public boolean performFinish() { // Saving the dialog settings page.saveDialogSettings(); // Getting the schemas to be exported and where to export them final Schema[] selectedSchemas = page.getSelectedSchemas(); final String exportDirectory = page.getExportDirectory(); try { getContainer().run( false, false, new IRunnableWithProgress() { public void run( IProgressMonitor monitor ) { monitor.beginTask( Messages.getString( "ExportSchemasAsOpenLdapWizard.ExportingSchemas" ), selectedSchemas.length ); //$NON-NLS-1$ for ( Schema schema : selectedSchemas ) { monitor.subTask( schema.getSchemaName() ); try { BufferedWriter buffWriter = new BufferedWriter( new FileWriter( exportDirectory + "/" //$NON-NLS-1$ + schema.getSchemaName() + ".schema" ) ); //$NON-NLS-1$ buffWriter.write( OpenLdapSchemaFileExporter.toSourceCode( schema ) ); buffWriter.close(); } catch ( IOException e ) { PluginUtils .logError( NLS .bind( Messages.getString( "ExportSchemasAsOpenLdapWizard.ErrorSavingSchema" ), new String[] { schema.getSchemaName() } ), //$NON-NLS-1$ e ); ViewUtils .displayErrorMessageDialog( Messages.getString( "ExportSchemasAsOpenLdapWizard.Error" ), NLS.bind( Messages.getString( "ExportSchemasAsOpenLdapWizard.ErrorSavingSchema" ), new String[] { schema.getSchemaName() } ) ); //$NON-NLS-1$ //$NON-NLS-2$ } monitor.worked( 1 ); } monitor.done(); } } ); } catch ( InvocationTargetException e ) { // Nothing to do (it will never occur) } catch ( InterruptedException e ) { // Nothing to do. } return true; } /** * {@inheritDoc} */ public void init( IWorkbench workbench, IStructuredSelection selection ) { setNeedsProgressMonitor( true ); } /** * Sets the selected projects. * * @param schemas * the schemas */ public void setSelectedSchemas( Schema[] schemas ) { selectedSchemas = schemas; } }
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/wizards/NewAttributeTypeWizard.java
plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/wizards/NewAttributeTypeWizard.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.wizards; 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.model.Schema; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jface.wizard.Wizard; import org.eclipse.ui.INewWizard; import org.eclipse.ui.IWorkbench; /** * This class represents the wizard to create a new AttributeType. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class NewAttributeTypeWizard extends Wizard implements INewWizard { public static final String ID = PluginConstants.NEW_WIZARD_NEW_ATTRIBUTE_TYPE_WIZARD; /** The selected schema */ private Schema selectedSchema; // The pages of the wizards private NewAttributeTypeGeneralWizardPage generalPage; private NewAttributeTypeContentWizardPage contentPage; private NewAttributeTypeMatchingRulesWizardPage matchingRulesPage; /** * {@inheritDoc} */ public void addPages() { // Creating pages generalPage = new NewAttributeTypeGeneralWizardPage(); generalPage.setSelectedSchema( selectedSchema ); contentPage = new NewAttributeTypeContentWizardPage(); matchingRulesPage = new NewAttributeTypeMatchingRulesWizardPage(); // Adding pages addPage( generalPage ); addPage( contentPage ); addPage( matchingRulesPage ); } /** * {@inheritDoc} */ public boolean performFinish() { // Creating the new attribute type AttributeType newAT = new AttributeType( generalPage.getOidValue() ); newAT.setSchemaName( generalPage.getSchemaValue() ); newAT.setNames( generalPage.getAliasesValue() ); newAT.setDescription( generalPage.getDescriptionValue() ); newAT.setSuperiorOid( contentPage.getSuperiorValue() ); newAT.setUsage( contentPage.getUsageValue() ); newAT.setSyntaxOid( contentPage.getSyntax() ); newAT.setSyntaxLength( contentPage.getSyntaxLengthValue() ); newAT.setObsolete( contentPage.getObsoleteValue() ); newAT.setSingleValued( contentPage.getSingleValueValue() ); newAT.setCollective( contentPage.getCollectiveValue() ); newAT.setUserModifiable( !contentPage.getNoUserModificationValue() ); newAT.setEqualityOid( matchingRulesPage.getEqualityMatchingRuleValue() ); newAT.setOrderingOid( matchingRulesPage.getOrderingMatchingRuleValue() ); newAT.setSubstringOid( matchingRulesPage.getSubstringMatchingRuleValue() ); // Adding the new attribute type Activator.getDefault().getSchemaHandler().addAttributeType( newAT ); // Saving the Dialog Settings OID History PluginUtils.saveDialogSettingsHistory( PluginConstants.DIALOG_SETTINGS_OID_HISTORY, newAT.getOid() ); return true; } /** * {@inheritDoc} */ public void init( IWorkbench workbench, IStructuredSelection selection ) { // Nothing to do. } /** * Sets the selected schema. * * @param schema * the selected schema */ public void setSelectedSchema( Schema schema ) { selectedSchema = 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/wizards/NewSchemaWizardPage.java
plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/wizards/NewSchemaWizardPage.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.wizards; import org.apache.directory.studio.schemaeditor.Activator; import org.apache.directory.studio.schemaeditor.PluginConstants; import org.apache.directory.studio.schemaeditor.controller.SchemaHandler; import org.eclipse.swt.SWT; import org.eclipse.swt.events.ModifyEvent; import org.eclipse.swt.events.ModifyListener; 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.Text; /** * This class represents the WizardPage of the NewSchemaWizard. * <p> * It is used to let the user create a new Schema * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class NewSchemaWizardPage extends AbstractWizardPage { /** The ProjectsHandler */ private SchemaHandler schemaHandler; // UI Fields private Text nameText; /** * Creates a new instance of NewSchemaWizardPage. */ protected NewSchemaWizardPage() { super( "NewSchemaWizardPage" ); //$NON-NLS-1$ setTitle( Messages.getString( "NewSchemaWizardPage.CreateSchema" ) ); //$NON-NLS-1$ setDescription( Messages.getString( "NewSchemaWizardPage.PleaseSpecifiyName" ) ); //$NON-NLS-1$ setImageDescriptor( Activator.getDefault().getImageDescriptor( PluginConstants.IMG_SCHEMA_NEW_WIZARD ) ); schemaHandler = Activator.getDefault().getSchemaHandler(); } /** * {@inheritDoc} */ public void createControl( Composite parent ) { Composite composite = new Composite( parent, SWT.NULL ); GridLayout layout = new GridLayout( 2, false ); composite.setLayout( layout ); // Name Label nameLabel = new Label( composite, SWT.NONE ); nameLabel.setText( Messages.getString( "NewSchemaWizardPage.SchemaName" ) ); //$NON-NLS-1$ nameText = new Text( composite, SWT.BORDER ); nameText.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) ); nameText.addModifyListener( new ModifyListener() { public void modifyText( ModifyEvent e ) { dialogChanged(); } } ); initFields(); setControl( composite ); } /** * Initializes the UI Fields. */ private void initFields() { if ( Activator.getDefault().getSchemaHandler() == null ) { nameText.setEnabled( false ); displayErrorMessage( Messages.getString( "NewSchemaWizardPage.ErrorNoSchemaProjectOpen" ) ); //$NON-NLS-1$ } else { displayErrorMessage( null ); setPageComplete( false ); } } /** * This method is called when the user modifies something in the UI. */ private void dialogChanged() { // Name if ( nameText.getText().equals( "" ) ) //$NON-NLS-1$ { displayErrorMessage( Messages.getString( "NewSchemaWizardPage.ErrorNoNameSpecified" ) ); //$NON-NLS-1$ return; } else if ( schemaHandler.isSchemaNameAlreadyTaken( nameText.getText() ) ) { displayErrorMessage( Messages.getString( "NewSchemaWizardPage.ErrorSchemaNameExists" ) ); //$NON-NLS-1$ return; } displayErrorMessage( null ); } /** * Gets the name of the schema. * * @return * the name of the schema */ public String getSchemaName() { return nameText.getText(); } }
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/wizards/ImportSchemasFromXmlWizard.java
plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/wizards/ImportSchemasFromXmlWizard.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.wizards; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import org.apache.directory.studio.common.core.jobs.StudioProgressMonitor; import org.apache.directory.studio.connection.core.jobs.StudioConnectionRunnableWithProgress; import org.apache.directory.studio.connection.core.jobs.StudioConnectionRunnableWithProgressAdapter; import org.apache.directory.studio.connection.ui.RunnableContextRunner; import org.apache.directory.studio.schemaeditor.Activator; import org.apache.directory.studio.schemaeditor.controller.SchemaHandler; import org.apache.directory.studio.schemaeditor.model.Schema; import org.apache.directory.studio.schemaeditor.model.io.XMLSchemaFileImportException; import org.apache.directory.studio.schemaeditor.model.io.XMLSchemaFileImporter; import org.apache.directory.studio.schemaeditor.model.io.XMLSchemaFileImporter.SchemaFileType; import org.apache.directory.studio.schemaeditor.model.schemachecker.SchemaChecker; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jface.wizard.Wizard; import org.eclipse.osgi.util.NLS; import org.eclipse.ui.IImportWizard; import org.eclipse.ui.IWorkbench; /** * This class represents the wizard to import schemas from XML format. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class ImportSchemasFromXmlWizard extends Wizard implements IImportWizard { /** The SchemaHandler */ private SchemaHandler schemaHandler; /** The SchemaChecker */ private SchemaChecker schemaChecker; // The pages of the wizard private ImportSchemasFromXmlWizardPage page; /** * {@inheritDoc} */ public void addPages() { // Creating pages page = new ImportSchemasFromXmlWizardPage(); // Adding pages addPage( page ); } /** * {@inheritDoc} */ public boolean performFinish() { // Saving the dialog settings page.saveDialogSettings(); // Getting the schemas to be imported final File[] selectedSchemasFiles = page.getSelectedSchemaFiles(); schemaChecker.disableModificationsListening(); StudioConnectionRunnableWithProgress runnable = new StudioConnectionRunnableWithProgressAdapter() { public void run( StudioProgressMonitor monitor ) { monitor.beginTask( Messages.getString( "ImportSchemasFromXmlWizard.ImportingSchemas" ), selectedSchemasFiles.length ); //$NON-NLS-1$ for ( File schemaFile : selectedSchemasFiles ) { monitor.subTask( schemaFile.getName() ); try { SchemaFileType schemaFileType = XMLSchemaFileImporter.getSchemaFileType( new FileInputStream( schemaFile ), schemaFile.getAbsolutePath() ); switch ( schemaFileType ) { case SINGLE: Schema importedSchema = XMLSchemaFileImporter.getSchema( new FileInputStream( schemaFile ), schemaFile.getAbsolutePath() ); importedSchema .setProject( Activator.getDefault().getProjectsHandler().getOpenProject() ); schemaHandler.addSchema( importedSchema ); break; case MULTIPLE: Schema[] schemas = XMLSchemaFileImporter.getSchemas( new FileInputStream( schemaFile ), schemaFile.getAbsolutePath() ); for ( Schema schema : schemas ) { schema.setProject( Activator.getDefault().getProjectsHandler().getOpenProject() ); schemaHandler.addSchema( schema ); } break; } } catch ( XMLSchemaFileImportException e ) { reportError( e, schemaFile, monitor ); } catch ( FileNotFoundException e ) { reportError( e, schemaFile, monitor ); } monitor.worked( 1 ); } monitor.done(); schemaChecker.enableModificationsListening(); } /** * Reports the error raised. * * @param e * the exception * @param schemaFile * the schema file * @param monitor * the monitor the error is reported to * */ private void reportError( Exception e, File schemaFile, StudioProgressMonitor monitor ) { String message = NLS.bind( Messages.getString( "ImportSchemasFromXmlWizard.ErrorImportingSchema" ), schemaFile.getName() ); //$NON-NLS-1$ monitor.reportError( message, e ); } public String getName() { return Messages.getString( "ImportSchemasFromXmlWizard.ImportingSchemas" ); //$NON-NLS-1$ } }; RunnableContextRunner.execute( runnable, getContainer(), true ); schemaChecker.enableModificationsListening(); return true; } /** * {@inheritDoc} */ public void init( IWorkbench workbench, IStructuredSelection selection ) { setNeedsProgressMonitor( true ); schemaHandler = Activator.getDefault().getSchemaHandler(); schemaChecker = Activator.getDefault().getSchemaChecker(); } }
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/wizards/NewProjectWizardSchemasSelectionPage.java
plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/wizards/NewProjectWizardSchemasSelectionPage.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.wizards; import org.apache.directory.studio.schemaeditor.Activator; import org.apache.directory.studio.schemaeditor.PluginConstants; import org.apache.directory.studio.schemaeditor.view.widget.CoreSchemasSelectionWidget; import org.apache.directory.studio.schemaeditor.view.widget.CoreSchemasSelectionWidget.ServerTypeEnum; import org.eclipse.jface.wizard.WizardPage; import org.eclipse.swt.widgets.Composite; /** * This class represents the Information Page of the NewProjectWizard. * <p> * It is used to let the user create a new Project * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class NewProjectWizardSchemasSelectionPage extends WizardPage { // UI Fields private CoreSchemasSelectionWidget coreSchemaSelectionWidget; /** * Creates a new instance of NewProjectWizardSchemasSelectionPage. */ protected NewProjectWizardSchemasSelectionPage() { super( "NewProjectWizardSchemasSelectionPage" ); //$NON-NLS-1$ setTitle( Messages.getString( "NewProjectWizardSchemasSelectionPage.CreateSchemaProject" ) ); //$NON-NLS-1$ setDescription( Messages.getString( "NewProjectWizardSchemasSelectionPage.PleaseSelectCoreSchemaForInclude" ) ); //$NON-NLS-1$ setImageDescriptor( Activator.getDefault().getImageDescriptor( PluginConstants.IMG_PROJECT_NEW_WIZARD ) ); } /** * {@inheritDoc} */ public void createControl( Composite parent ) { coreSchemaSelectionWidget = new CoreSchemasSelectionWidget(); Composite composite = coreSchemaSelectionWidget.createWidget( parent ); coreSchemaSelectionWidget.init( ServerTypeEnum.APACHE_DS ); setControl( composite ); } /** * Gets the schemas selected by the User. * * @return * the selected schemas */ public String[] getSelectedSchemas() { return coreSchemaSelectionWidget.getCheckedCoreSchemas(); } /** * Gets the Server Type * * @return * the Server Type */ public ServerTypeEnum getServerType() { return coreSchemaSelectionWidget.getServerType(); } }
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/wizards/NewObjectClassMandatoryAttributesPage.java
plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/wizards/NewObjectClassMandatoryAttributesPage.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.wizards; 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.PluginConstants; import org.apache.directory.studio.schemaeditor.view.ViewUtils; import org.apache.directory.studio.schemaeditor.view.dialogs.AttributeTypeSelectionDialog; import org.eclipse.jface.dialogs.Dialog; import org.eclipse.jface.viewers.ArrayContentProvider; import org.eclipse.jface.viewers.ISelectionChangedListener; import org.eclipse.jface.viewers.LabelProvider; import org.eclipse.jface.viewers.SelectionChangedEvent; import org.eclipse.jface.viewers.StructuredSelection; import org.eclipse.jface.viewers.TableViewer; import org.eclipse.jface.wizard.WizardPage; import org.eclipse.osgi.util.NLS; import org.eclipse.swt.SWT; 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.Group; import org.eclipse.swt.widgets.Table; /** * This class represents the Mandatory Attribute Types WizardPage of the NewObjectClassWizard. * <p> * It is used to let the user specify the mandatory attribute types for the object class. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class NewObjectClassMandatoryAttributesPage extends WizardPage { /** The mandatory attribute types list */ private List<AttributeType> mandatoryAttributeTypesList; // UI Fields private TableViewer mandatoryAttributeTypesTableViewer; private Button mandatoryAttributeTypesAddButton; private Button mandatoryAttributeTypesRemoveButton; /** * Creates a new instance of NewObjectClassMandatoryAttributesPage. */ protected NewObjectClassMandatoryAttributesPage() { super( "NewObjectClassMandatoryAttributesPage" ); //$NON-NLS-1$ setTitle( Messages.getString( "NewObjectClassMandatoryAttributesPage.MandatoryAttributeTypes" ) ); //$NON-NLS-1$ setDescription( Messages .getString( "NewObjectClassMandatoryAttributesPage.SpecifiyMandatoryAttributeTypeForObjectClass" ) ); //$NON-NLS-1$ setImageDescriptor( Activator.getDefault().getImageDescriptor( PluginConstants.IMG_OBJECT_CLASS_NEW_WIZARD ) ); mandatoryAttributeTypesList = new ArrayList<AttributeType>(); } /** * {@inheritDoc} */ public void createControl( Composite parent ) { Composite composite = new Composite( parent, SWT.NULL ); GridLayout layout = new GridLayout(); composite.setLayout( layout ); // Mandatory Attribute Types Group Group mandatoryAttributeTypesGroup = new Group( composite, SWT.NONE ); mandatoryAttributeTypesGroup.setText( Messages .getString( "NewObjectClassMandatoryAttributesPage.MandatoryAttributeTypes" ) ); //$NON-NLS-1$ mandatoryAttributeTypesGroup.setLayout( new GridLayout( 2, false ) ); mandatoryAttributeTypesGroup.setLayoutData( new GridData( SWT.FILL, SWT.FILL, true, true ) ); // Mandatory Attribute Types Table mandatoryAttributeTypesTable = new Table( mandatoryAttributeTypesGroup, SWT.BORDER ); GridData mandatoryAttributeTypesTableGridData = new GridData( SWT.FILL, SWT.FILL, true, true, 1, 2 ); mandatoryAttributeTypesTableGridData.heightHint = 100; mandatoryAttributeTypesTable.setLayoutData( mandatoryAttributeTypesTableGridData ); mandatoryAttributeTypesTableViewer = new TableViewer( mandatoryAttributeTypesTable ); mandatoryAttributeTypesTableViewer.setContentProvider( new ArrayContentProvider() ); mandatoryAttributeTypesTableViewer.setLabelProvider( new LabelProvider() { public Image getImage( Object element ) { if ( element instanceof AttributeType ) { return Activator.getDefault().getImage( PluginConstants.IMG_ATTRIBUTE_TYPE ); } // Default return super.getImage( element ); } public String getText( Object element ) { if ( element instanceof AttributeType ) { AttributeType at = ( AttributeType ) element; List<String> names = at.getNames(); if ( ( names != null ) && ( names.size() > 0 ) ) { return NLS .bind( Messages.getString( "NewObjectClassMandatoryAttributesPage.AliasOID" ), new String[] { ViewUtils.concateAliases( names ), at.getOid() } ); //$NON-NLS-1$ } else { return NLS .bind( Messages.getString( "NewObjectClassMandatoryAttributesPage.NoneOID" ), new String[] { at.getOid() } ); //$NON-NLS-1$ } } // Default return super.getText( element ); } } ); mandatoryAttributeTypesTableViewer.setInput( mandatoryAttributeTypesList ); mandatoryAttributeTypesTableViewer.addSelectionChangedListener( new ISelectionChangedListener() { public void selectionChanged( SelectionChangedEvent event ) { mandatoryAttributeTypesRemoveButton.setEnabled( !event.getSelection().isEmpty() ); } } ); mandatoryAttributeTypesAddButton = new Button( mandatoryAttributeTypesGroup, SWT.PUSH ); mandatoryAttributeTypesAddButton.setText( Messages.getString( "NewObjectClassMandatoryAttributesPage.Add" ) ); //$NON-NLS-1$ mandatoryAttributeTypesAddButton.setLayoutData( new GridData( SWT.FILL, SWT.NONE, false, false ) ); mandatoryAttributeTypesAddButton.addSelectionListener( new SelectionAdapter() { public void widgetSelected( SelectionEvent arg0 ) { addMandatoryAttributeType(); } } ); mandatoryAttributeTypesRemoveButton = new Button( mandatoryAttributeTypesGroup, SWT.PUSH ); mandatoryAttributeTypesRemoveButton.setText( Messages .getString( "NewObjectClassMandatoryAttributesPage.Remove" ) ); //$NON-NLS-1$ mandatoryAttributeTypesRemoveButton.setLayoutData( new GridData( SWT.FILL, SWT.NONE, false, false ) ); mandatoryAttributeTypesRemoveButton.addSelectionListener( new SelectionAdapter() { public void widgetSelected( SelectionEvent arg0 ) { removeMandatoryAttributeType(); } } ); mandatoryAttributeTypesRemoveButton.setEnabled( false ); setControl( composite ); } /** * This method is called when the "Add" button of the mandatory * attribute types table is selected. */ private void addMandatoryAttributeType() { AttributeTypeSelectionDialog dialog = new AttributeTypeSelectionDialog(); List<AttributeType> hiddenAttributes = new ArrayList<AttributeType>(); hiddenAttributes.addAll( mandatoryAttributeTypesList ); dialog.setHiddenAttributeTypes( hiddenAttributes ); if ( dialog.open() == Dialog.OK ) { mandatoryAttributeTypesList.add( dialog.getSelectedAttributeType() ); updateMandatoryAttributeTypesTableTable(); } } /** * This method is called when the "Remove" button of the mandatory * attribute types table is selected. */ private void removeMandatoryAttributeType() { StructuredSelection selection = ( StructuredSelection ) mandatoryAttributeTypesTableViewer.getSelection(); if ( !selection.isEmpty() ) { mandatoryAttributeTypesList.remove( selection.getFirstElement() ); updateMandatoryAttributeTypesTableTable(); } } /** * Updates the mandatory attribute types table. */ private void updateMandatoryAttributeTypesTableTable() { Collections.sort( mandatoryAttributeTypesList, new Comparator<AttributeType>() { public int compare( AttributeType o1, AttributeType o2 ) { List<String> at1Names = o1.getNames(); List<String> at2Names = o2.getNames(); if ( ( at1Names != null ) && ( at2Names != null ) && ( at1Names.size() > 0 ) && ( at2Names.size() > 0 ) ) { return at1Names.get( 0 ).compareToIgnoreCase( at2Names.get( 0 ) ); } // Default return 0; } } ); mandatoryAttributeTypesTableViewer.refresh(); } /** * Gets the mandatory attribute types. * * @return * the mandatory attributes types */ public List<AttributeType> getMandatoryAttributeTypes() { return mandatoryAttributeTypesList; } /** * Gets the names of the mandatory attribute types. * * @return * the names of the mandatory attributes types */ public List<String> getMandatoryAttributeTypesNames() { List<String> names = new ArrayList<String>(); for ( AttributeType at : mandatoryAttributeTypesList ) { names.add( at.getName() ); } return names; } }
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/wizards/NewProjectWizardConnectionSelectionPage.java
plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/wizards/NewProjectWizardConnectionSelectionPage.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.wizards; import org.apache.directory.studio.connection.core.Connection; import org.apache.directory.studio.connection.core.ConnectionCorePlugin; import org.apache.directory.studio.connection.ui.widgets.ConnectionActionGroup; import org.apache.directory.studio.connection.ui.widgets.ConnectionConfiguration; import org.apache.directory.studio.connection.ui.widgets.ConnectionUniversalListener; import org.apache.directory.studio.connection.ui.widgets.ConnectionWidget; import org.apache.directory.studio.schemaeditor.Activator; import org.apache.directory.studio.schemaeditor.PluginConstants; import org.eclipse.jface.viewers.ISelection; 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.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Label; /** * This class represents the Information Page of the NewProjectWizard. * <p> * It is used to let the user create a new Project * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class NewProjectWizardConnectionSelectionPage extends AbstractWizardPage { private ConnectionConfiguration configuration; private ConnectionUniversalListener universalListener; // UI Fields private ConnectionWidget connectionWidget; private ConnectionActionGroup actionGroup; /** * Creates a new instance of NewProjectWizardConnectionSelectionPage. */ protected NewProjectWizardConnectionSelectionPage() { super( "NewProjectWizardConnectionSelectionPage" ); //$NON-NLS-1$ setTitle( Messages.getString( "NewProjectWizardConnectionSelectionPage.CreateSchemaProject" ) ); //$NON-NLS-1$ setDescription( Messages.getString( "NewProjectWizardConnectionSelectionPage.PleaseSelectConnection" ) ); //$NON-NLS-1$ setImageDescriptor( Activator.getDefault().getImageDescriptor( PluginConstants.IMG_PROJECT_NEW_WIZARD ) ); setPageComplete( false ); } /** * {@inheritDoc} */ public void createControl( Composite parent ) { Composite composite = new Composite( parent, SWT.NONE ); composite.setLayout( new GridLayout() ); // Choose A Connection Label Label label = new Label( composite, SWT.NONE ); label.setText( Messages.getString( "NewProjectWizardConnectionSelectionPage.ChooseConnection" ) ); //$NON-NLS-1$ label.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) ); // Creating configuration configuration = new ConnectionConfiguration(); // Creating Connection Widget connectionWidget = new ConnectionWidget( configuration, null ); connectionWidget.createWidget( composite ); connectionWidget.setInput( ConnectionCorePlugin.getDefault().getConnectionFolderManager() ); connectionWidget.getViewer().addSelectionChangedListener( new ISelectionChangedListener() { public void selectionChanged( SelectionChangedEvent event ) { validatePage(); } } ); // creating the listener universalListener = new ConnectionUniversalListener( connectionWidget.getViewer() ); // create actions and context menu (and register global actions) actionGroup = new ConnectionActionGroup( connectionWidget, configuration ); actionGroup.fillToolBar( connectionWidget.getToolBarManager() ); actionGroup.fillMenu( connectionWidget.getMenuManager() ); actionGroup.fillContextMenu( connectionWidget.getContextMenuManager() ); actionGroup.activateGlobalActionHandlers(); initFields(); setControl( composite ); } /** * Initializes the UI Fields. */ private void initFields() { displayErrorMessage( null ); setPageComplete( false ); } /** * Validates the page. */ private void validatePage() { ISelection selection = connectionWidget.getViewer().getSelection(); if ( selection.isEmpty() ) { displayErrorMessage( Messages .getString( "NewProjectWizardConnectionSelectionPage.ErrorNoConnectionSelected" ) ); //$NON-NLS-1$ return; } displayErrorMessage( null ); } /** * Gets the selected connection. * * @return * the selection connection */ public Connection getSelectedConnection() { return ( Connection ) ( ( StructuredSelection ) connectionWidget.getViewer().getSelection() ).getFirstElement(); } /** * {@inheritDoc} */ public void dispose() { if ( configuration != null ) { actionGroup.dispose(); actionGroup = null; configuration.dispose(); configuration = null; universalListener.dispose(); universalListener = null; connectionWidget.dispose(); connectionWidget = null; } 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/wizards/MergeSchemasWizard.java
plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/wizards/MergeSchemasWizard.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.wizards; import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; import org.apache.directory.api.ldap.model.schema.AbstractSchemaObject; import org.apache.directory.api.ldap.model.schema.AttributeType; import org.apache.directory.api.ldap.model.schema.ObjectClass; import org.apache.directory.studio.common.ui.dialogs.MessageDialogWithTextarea; import org.apache.directory.studio.schemaeditor.Activator; import org.apache.directory.studio.schemaeditor.model.Project; import org.apache.directory.studio.schemaeditor.model.Schema; import org.apache.directory.studio.schemaeditor.view.wizards.MergeSchemasSelectionWizardPage.AttributeTypeFolder; import org.apache.directory.studio.schemaeditor.view.wizards.MergeSchemasSelectionWizardPage.AttributeTypeWrapper; import org.apache.directory.studio.schemaeditor.view.wizards.MergeSchemasSelectionWizardPage.ObjectClassFolder; import org.apache.directory.studio.schemaeditor.view.wizards.MergeSchemasSelectionWizardPage.ObjectClassWrapper; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jface.wizard.Wizard; import org.eclipse.osgi.util.NLS; import org.eclipse.ui.IImportWizard; import org.eclipse.ui.IWorkbench; /** * This class represents the wizard to merge schema projects. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class MergeSchemasWizard extends Wizard implements IImportWizard { // The pages of the wizard private MergeSchemasSelectionWizardPage selectionPage; private MergeSchemasOptionsWizardPage optionsPage; /** * {@inheritDoc} */ public void addPages() { // Creating pages selectionPage = new MergeSchemasSelectionWizardPage(); optionsPage = new MergeSchemasOptionsWizardPage(); // Adding pages addPage( selectionPage ); addPage( optionsPage ); } /** * {@inheritDoc} */ public boolean performFinish() { Object[] sourceObjects = selectionPage.getSelectedObjects(); boolean replaceUnknownSyntax = optionsPage.isReplaceUnknownSyntax(); boolean mergeDependencies = optionsPage.isMergeDependencies(); boolean pullUpAttributes = optionsPage.isPullUpAttributes(); List<String> errorMessages = new ArrayList<String>(); mergeObjects( sourceObjects, errorMessages, replaceUnknownSyntax, mergeDependencies, pullUpAttributes ); if ( !errorMessages.isEmpty() ) { StringBuilder sb = new StringBuilder(); for ( String errorMessage : errorMessages ) { sb.append( errorMessage ); sb.append( '\n' ); } new MessageDialogWithTextarea( getShell(), Messages.getString( "MergeSchemasWizard.MergeResultTitle" ), //$NON-NLS-1$ Messages.getString( "MergeSchemasWizard.MergeResultMessage" ), sb.toString() ).open(); //$NON-NLS-1$ } return true; } private void mergeObjects( Object[] sourceObjects, List<String> errorMessages, boolean replaceUnknownSyntax, boolean mergeDependencies, boolean pullUpAttributes ) { /* * List of already processed schema objects. Used to avoid that schema objects are process multiple time. */ Set<Object> processedObjects = new HashSet<Object>(); /* * List of created target schemas. */ Map<String, Schema> targetSchemas = new HashMap<String, Schema>(); Project targetProject = Activator.getDefault().getProjectsHandler().getOpenProject(); // merge all source objects to the target project for ( Object sourceObject : sourceObjects ) { if ( sourceObject instanceof Project ) { Project sourceProject = ( Project ) sourceObject; for ( Schema sourceSchema : sourceProject.getSchemaHandler().getSchemas() ) { Schema targetSchema = getTargetSchema( sourceSchema.getProject(), targetProject, targetSchemas ); mergeSchema( sourceSchema, targetProject, targetSchema, processedObjects, errorMessages, replaceUnknownSyntax, mergeDependencies, pullUpAttributes ); } } if ( sourceObject instanceof Schema ) { Schema sourceSchema = ( Schema ) sourceObject; Schema targetSchema = getTargetSchema( sourceSchema.getProject(), targetProject, targetSchemas ); mergeSchema( sourceSchema, targetProject, targetSchema, processedObjects, errorMessages, replaceUnknownSyntax, mergeDependencies, pullUpAttributes ); } if ( sourceObject instanceof AttributeTypeFolder ) { AttributeTypeFolder atf = ( AttributeTypeFolder ) sourceObject; Schema targetSchema = getTargetSchema( atf.schema.getProject(), targetProject, targetSchemas ); List<AttributeType> sourceAttributeTypes = atf.schema.getAttributeTypes(); for ( AttributeType sourceAttributeType : sourceAttributeTypes ) { mergeAttributeType( sourceAttributeType, targetProject, targetSchema, processedObjects, errorMessages, replaceUnknownSyntax, mergeDependencies, pullUpAttributes ); } } if ( sourceObject instanceof ObjectClassFolder ) { ObjectClassFolder ocf = ( ObjectClassFolder ) sourceObject; Schema targetSchema = getTargetSchema( ocf.schema.getProject(), targetProject, targetSchemas ); List<ObjectClass> sourceObjectClasses = ocf.schema.getObjectClasses(); for ( ObjectClass sourceObjectClass : sourceObjectClasses ) { mergeObjectClass( sourceObjectClass, targetProject, targetSchema, processedObjects, errorMessages, replaceUnknownSyntax, mergeDependencies, pullUpAttributes ); } } if ( sourceObject instanceof AttributeTypeWrapper ) { AttributeTypeWrapper atw = ( AttributeTypeWrapper ) sourceObject; Schema targetSchema = getTargetSchema( atw.folder.schema.getProject(), targetProject, targetSchemas ); mergeAttributeType( atw.attributeType, targetProject, targetSchema, processedObjects, errorMessages, replaceUnknownSyntax, mergeDependencies, pullUpAttributes ); } if ( sourceObject instanceof ObjectClassWrapper ) { ObjectClassWrapper ocw = ( ObjectClassWrapper ) sourceObject; Schema targetSchema = getTargetSchema( ocw.folder.schema.getProject(), targetProject, targetSchemas ); mergeObjectClass( ocw.objectClass, targetProject, targetSchema, processedObjects, errorMessages, replaceUnknownSyntax, mergeDependencies, pullUpAttributes ); } } //add created target schemas to project for ( Schema targetSchema : targetSchemas.values() ) { if ( !targetProject.getSchemaHandler().getSchemas().contains( targetSchema ) ) { targetProject.getSchemaHandler().addSchema( targetSchema ); } } } private Schema getTargetSchema( Project sourceProject, Project targetProject, Map<String, Schema> targetSchemas ) { String targetSchemaName = "merge-from-" + sourceProject.getName(); //$NON-NLS-1$ Schema targetSchema = targetProject.getSchemaHandler().getSchema( targetSchemaName ); if ( targetSchema != null ) { targetProject.getSchemaHandler().removeSchema( targetSchema ); } else if ( targetSchemas.containsKey( targetSchemaName ) ) { targetSchema = targetSchemas.get( targetSchemaName ); } else { targetSchema = new Schema( targetSchemaName ); targetSchema.setProject( targetProject ); } targetSchemas.put( targetSchemaName, targetSchema ); return targetSchema; } /** * Merges all attribute types and object classes and form the given sourceSchema to the targetSchema. */ private void mergeSchema( Schema sourceSchema, Project targetProject, Schema targetSchema, Set<Object> processedObjects, List<String> errorMessages, boolean replaceUnknownSyntax, boolean mergeDependencies, boolean pullUpAttributes ) { List<AttributeType> sourceAttributeTypes = sourceSchema.getAttributeTypes(); for ( AttributeType sourceAttributeType : sourceAttributeTypes ) { mergeAttributeType( sourceAttributeType, targetProject, targetSchema, processedObjects, errorMessages, replaceUnknownSyntax, mergeDependencies, pullUpAttributes ); } List<ObjectClass> sourceObjectClasses = sourceSchema.getObjectClasses(); for ( ObjectClass sourceObjectClass : sourceObjectClasses ) { mergeObjectClass( sourceObjectClass, targetProject, targetSchema, processedObjects, errorMessages, replaceUnknownSyntax, mergeDependencies, pullUpAttributes ); } } /** * Merges the given attribute type to the targetSchema. */ private void mergeAttributeType( AttributeType sourceAttributeType, Project targetProject, Schema targetSchema, Set<Object> processedObjects, List<String> errorMessages, boolean replaceUnknownSyntax, boolean mergeDependencies, boolean pullUpAttributes ) { if ( processedObjects.contains( sourceAttributeType ) ) { return; } processedObjects.add( sourceAttributeType ); // check if attribute (identified by OID or name) already exists in the project AttributeType targetAttributeType = targetProject.getSchemaHandler().getAttributeType( sourceAttributeType.getOid() ); if ( targetAttributeType == null ) { for ( String name : sourceAttributeType.getNames() ) { targetAttributeType = targetProject.getSchemaHandler().getAttributeType( name ); if ( targetAttributeType != null ) { break; } } } // check if OID or alias name already exist in target project boolean oidOrAliasAlreadyTaken = targetProject.getSchemaHandler().isOidAlreadyTaken( sourceAttributeType.getOid() ); if ( !oidOrAliasAlreadyTaken ) { for ( String name : sourceAttributeType.getNames() ) { oidOrAliasAlreadyTaken = targetProject.getSchemaHandler().isAliasAlreadyTakenForAttributeType( name ); if ( oidOrAliasAlreadyTaken ) { break; } } } if ( targetAttributeType != null ) { errorMessages.add( NLS.bind( Messages.getString( "MergeSchemasWizard.AttributeTypeExistsInTargetProject" ), //$NON-NLS-1$ getIdString( sourceAttributeType ) ) ); } else { if ( oidOrAliasAlreadyTaken ) { errorMessages.add( NLS.bind( Messages.getString( "MergeSchemasWizard.OidOrAliasAlreadyTaken" ), //$NON-NLS-1$ getIdString( sourceAttributeType ) ) ); } else { // remove attribute type if already there from previous merge AttributeType at = targetSchema.getAttributeType( sourceAttributeType.getOid() ); if ( at != null ) { targetSchema.removeAttributeType( at ); } // clone attribute type AttributeType clonedAttributeType = new AttributeType( sourceAttributeType.getOid() ); clonedAttributeType.setNames( sourceAttributeType.getNames() ); clonedAttributeType.setDescription( sourceAttributeType.getDescription() ); clonedAttributeType.setSuperiorOid( sourceAttributeType.getSuperiorOid() ); clonedAttributeType.setUsage( sourceAttributeType.getUsage() ); clonedAttributeType.setSyntaxOid( sourceAttributeType.getSyntaxOid() ); clonedAttributeType.setSyntaxLength( sourceAttributeType.getSyntaxLength() ); clonedAttributeType.setObsolete( sourceAttributeType.isObsolete() ); clonedAttributeType.setCollective( sourceAttributeType.isCollective() ); clonedAttributeType.setSingleValued( sourceAttributeType.isSingleValued() ); clonedAttributeType.setUserModifiable( sourceAttributeType.isUserModifiable() ); clonedAttributeType.setEqualityOid( sourceAttributeType.getEqualityOid() ); clonedAttributeType.setOrderingOid( sourceAttributeType.getOrderingOid() ); clonedAttributeType.setSubstringOid( sourceAttributeType.getSubstringOid() ); clonedAttributeType.setSchemaName( targetSchema.getSchemaName() ); // if no/unknown syntax: set "Directory String" syntax and appropriate matching rules if ( replaceUnknownSyntax ) { if ( clonedAttributeType.getSyntaxOid() == null || targetProject.getSchemaHandler().getSyntax( clonedAttributeType.getSyntaxOid() ) == null ) { errorMessages.add( NLS.bind( Messages.getString( "MergeSchemasWizard.ReplacedSyntax" ), //$NON-NLS-1$ new String[] { getIdString( sourceAttributeType ), clonedAttributeType.getSyntaxOid(), "1.3.6.1.4.1.1466.115.121.1.15 (Directory String)" } ) ); //$NON-NLS-1$ clonedAttributeType.setSyntaxOid( "1.3.6.1.4.1.1466.115.121.1.15" ); //$NON-NLS-1$ clonedAttributeType.setEqualityOid( "caseIgnoreMatch" ); //$NON-NLS-1$ clonedAttributeType.setOrderingOid( null ); clonedAttributeType.setSubstringOid( "caseIgnoreSubstringsMatch" ); //$NON-NLS-1$ } } // TODO: if unknown (single) matching rule: set appropriate matching rule according to syntax // TODO: if no (all) matching rules: set appropriate matching rules according to syntax // merge dependencies: super attribute type if ( mergeDependencies ) { String superiorName = clonedAttributeType.getSuperiorOid(); if ( superiorName != null ) { AttributeType superiorAttributeType = Activator.getDefault().getSchemaHandler() .getAttributeType( superiorName ); if ( superiorAttributeType != null ) { mergeAttributeType( superiorAttributeType, targetProject, targetSchema, processedObjects, errorMessages, replaceUnknownSyntax, mergeDependencies, pullUpAttributes ); } } } targetSchema.addAttributeType( clonedAttributeType ); } } } /** * Merges the given object class to the targetSchema. */ private void mergeObjectClass( ObjectClass sourceObjectClass, Project targetProject, Schema targetSchema, Set<Object> processedObjects, List<String> errorMessages, boolean replaceUnknownSyntax, boolean mergeDependencies, boolean pullUpAttributes ) { if ( processedObjects.contains( sourceObjectClass ) ) { return; } processedObjects.add( sourceObjectClass ); // check if object class (identified by OID or alias name) already exists in the target project ObjectClass targetObjectClass = targetProject.getSchemaHandler() .getObjectClass( sourceObjectClass.getOid() ); if ( targetObjectClass == null ) { for ( String name : sourceObjectClass.getNames() ) { targetObjectClass = targetProject.getSchemaHandler().getObjectClass( name ); if ( targetObjectClass != null ) { break; } } } // check if OID or alias name already exist in target project boolean oidOrAliasAlreadyTaken = targetProject.getSchemaHandler().isOidAlreadyTaken( sourceObjectClass.getOid() ); if ( !oidOrAliasAlreadyTaken ) { for ( String name : sourceObjectClass.getNames() ) { oidOrAliasAlreadyTaken = targetProject.getSchemaHandler().isAliasAlreadyTakenForObjectClass( name ); if ( oidOrAliasAlreadyTaken ) { break; } } } if ( targetObjectClass != null ) { errorMessages.add( NLS.bind( Messages.getString( "MergeSchemasWizard.ObjectClassExistsInTargetProject" ), //$NON-NLS-1$ getIdString( sourceObjectClass ) ) ); } else { if ( oidOrAliasAlreadyTaken ) { errorMessages.add( NLS.bind( Messages.getString( "MergeSchemasWizard.OidOrAliasAlreadyTaken" ), //$NON-NLS-1$ getIdString( sourceObjectClass ) ) ); } else { // remove object class if already there from previous merge ObjectClass oc = targetSchema.getObjectClass( sourceObjectClass.getOid() ); if ( oc != null ) { targetSchema.removeObjectClass( oc ); } // create object class ObjectClass clonedObjectClass = new ObjectClass( sourceObjectClass.getOid() ); clonedObjectClass.setOid( sourceObjectClass.getOid() ); clonedObjectClass.setNames( sourceObjectClass.getNames() ); clonedObjectClass.setDescription( sourceObjectClass.getDescription() ); clonedObjectClass.setSuperiorOids( sourceObjectClass.getSuperiorOids() ); clonedObjectClass.setType( sourceObjectClass.getType() ); clonedObjectClass.setObsolete( sourceObjectClass.isObsolete() ); clonedObjectClass.setMustAttributeTypeOids( sourceObjectClass.getMustAttributeTypeOids() ); clonedObjectClass.setMayAttributeTypeOids( sourceObjectClass.getMayAttributeTypeOids() ); clonedObjectClass.setSchemaName( targetSchema.getSchemaName() ); // merge dependencies: super object classes and must/may attributes if ( mergeDependencies ) { List<String> superClassesNames = clonedObjectClass.getSuperiorOids(); if ( superClassesNames != null ) { for ( String superClassName : superClassesNames ) { if ( superClassName != null ) { ObjectClass superSourceObjectClass = Activator.getDefault().getSchemaHandler() .getObjectClass( superClassName ); ObjectClass superTargetObjectClass = targetProject.getSchemaHandler() .getObjectClass( superClassName ); if ( superSourceObjectClass != null ) { if ( superTargetObjectClass == null ) { mergeObjectClass( superSourceObjectClass, targetProject, targetSchema, processedObjects, errorMessages, replaceUnknownSyntax, mergeDependencies, pullUpAttributes ); } else { // pull-up may and must attributes to this OC if super already exists in target if ( pullUpAttributes ) { pullUpAttributes( clonedObjectClass, superSourceObjectClass, superTargetObjectClass ); } } } } } } List<String> mustNamesList = clonedObjectClass.getMustAttributeTypeOids(); List<String> mayNamesList = clonedObjectClass.getMayAttributeTypeOids(); List<String> attributeNames = new ArrayList<String>(); if ( mustNamesList != null ) { attributeNames.addAll( mustNamesList ); } if ( mayNamesList != null ) { attributeNames.addAll( mayNamesList ); } for ( String attributeName : attributeNames ) { if ( attributeName != null ) { AttributeType attributeType = Activator.getDefault().getSchemaHandler() .getAttributeType( attributeName ); if ( attributeType != null ) { mergeAttributeType( attributeType, targetProject, targetSchema, processedObjects, errorMessages, replaceUnknownSyntax, mergeDependencies, pullUpAttributes ); } } } } targetSchema.addObjectClass( clonedObjectClass ); } } } private void pullUpAttributes( ObjectClass targetObjectClass, ObjectClass sourceSuperObjectClass, ObjectClass targetSuperObjectClass ) { // must Set<String> sourceMustAttributeNames = new HashSet<String>(); fetchAttributes( sourceMustAttributeNames, sourceSuperObjectClass, true ); Set<String> targetMustAttributeNames = new HashSet<String>(); fetchAttributes( targetMustAttributeNames, targetSuperObjectClass, true ); sourceMustAttributeNames.removeAll( targetMustAttributeNames ); if ( !sourceMustAttributeNames.isEmpty() ) { sourceMustAttributeNames.addAll( targetObjectClass.getMustAttributeTypeOids() ); targetObjectClass.setMustAttributeTypeOids( new ArrayList<String>( sourceMustAttributeNames ) ); } // may Set<String> sourceMayAttributeNames = new HashSet<String>(); fetchAttributes( sourceMayAttributeNames, sourceSuperObjectClass, false ); Set<String> targetMayAttributeNames = new HashSet<String>(); fetchAttributes( targetMayAttributeNames, targetSuperObjectClass, false ); sourceMayAttributeNames.removeAll( targetMayAttributeNames ); if ( !sourceMayAttributeNames.isEmpty() ) { sourceMayAttributeNames.addAll( targetObjectClass.getMayAttributeTypeOids() ); targetObjectClass.setMayAttributeTypeOids( new ArrayList<String>( sourceMayAttributeNames ) ); } } private void fetchAttributes( Set<String> attributeNameList, ObjectClass oc, boolean must ) { List<String> attributeNames = must ? oc.getMustAttributeTypeOids() : oc.getMayAttributeTypeOids(); attributeNameList.addAll( attributeNames ); for ( String superClassName : oc.getSuperiorOids() ) { ObjectClass superObjectClass = Activator.getDefault().getSchemaHandler().getObjectClass( superClassName ); fetchAttributes( attributeNameList, superObjectClass, must ); } } private String getIdString( AbstractSchemaObject schemaObject ) { StringBuilder sb = new StringBuilder(); sb.append( '[' ); if ( schemaObject.getNames() != null ) { for ( String name : schemaObject.getNames() ) { sb.append( name ); sb.append( ',' ); } } sb.append( schemaObject.getOid() ); sb.append( ']' ); return sb.toString(); } /** * {@inheritDoc} */ public void init( IWorkbench workbench, IStructuredSelection 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/wizards/NewSchemaWizard.java
plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/wizards/NewSchemaWizard.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.wizards; import org.apache.directory.studio.schemaeditor.Activator; import org.apache.directory.studio.schemaeditor.PluginConstants; import org.apache.directory.studio.schemaeditor.model.Schema; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jface.wizard.Wizard; import org.eclipse.ui.INewWizard; import org.eclipse.ui.IWorkbench; /** * This class represents the wizard to create a new Schema. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class NewSchemaWizard extends Wizard implements INewWizard { public static final String ID = PluginConstants.NEW_WIZARD_NEW_SCHEMA_WIZARD; // The pages of the wizard private NewSchemaWizardPage page; /** * {@inheritDoc} */ public void addPages() { // Creating pages page = new NewSchemaWizardPage(); // Adding pages addPage( page ); } /** * {@inheritDoc} */ public boolean performFinish() { Schema schema = new Schema( page.getSchemaName() ); schema.setProject( Activator.getDefault().getProjectsHandler().getOpenProject() ); Activator.getDefault().getSchemaHandler().addSchema( schema ); return true; } /** * {@inheritDoc} */ public void init( IWorkbench workbench, IStructuredSelection selection ) { // Nothing to do. } }
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/wizards/CommitChangesWizard.java
plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/wizards/CommitChangesWizard.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.wizards; import org.apache.directory.studio.schemaeditor.Activator; import org.apache.directory.studio.schemaeditor.model.DependenciesComputer; import org.apache.directory.studio.schemaeditor.model.DependenciesComputer.DependencyComputerException; import org.apache.directory.studio.schemaeditor.model.Project; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jface.wizard.Wizard; import org.eclipse.ui.IExportWizard; import org.eclipse.ui.IWorkbench; /** * This class represents the wizard to commit changes to the Apache Directory Server. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class CommitChangesWizard extends Wizard implements IExportWizard { /** The flag to know if the Schema contains errors */ private boolean schemaContainsErrors = false; /** The project */ private Project project; /** The DependenciesComputer */ private DependenciesComputer dependenciesComputer; // The pages of the wizard private CommitChangesInformationWizardPage commitChangesInformation; private CommitChangesDifferencesWizardPage commitChangesDifferences; /** * {@inheritDoc} */ public void addPages() { // Creating pages commitChangesInformation = new CommitChangesInformationWizardPage(); commitChangesDifferences = new CommitChangesDifferencesWizardPage(); // Adding pages addPage( commitChangesInformation ); addPage( commitChangesDifferences ); } /** * {@inheritDoc} */ public boolean performFinish() { // final List<Schema> orderedSchemas = dependenciesComputer.getDependencyOrderedSchemasList(); // // try // { // getContainer().run( false, false, new IRunnableWithProgress() // { // public void run( IProgressMonitor monitor ) // { // //TODO implement // } // } ); // } // catch ( InvocationTargetException e ) // { // // Nothing to do (it will never occur) // } // catch ( InterruptedException e ) // { // // Nothing to do. // } return true; } /** * {@inheritDoc} */ public boolean canFinish() { if ( schemaContainsErrors ) { return false; } else { return ( getContainer().getCurrentPage() instanceof CommitChangesDifferencesWizardPage ); } } /** * {@inheritDoc} */ public void init( IWorkbench workbench, IStructuredSelection selection ) { setNeedsProgressMonitor( true ); project = Activator.getDefault().getProjectsHandler().getOpenProject(); try { dependenciesComputer = new DependenciesComputer( project.getSchemaHandler().getSchemas() ); } catch ( DependencyComputerException e ) { schemaContainsErrors = true; } } /** * Gets the SchemaContainsErrors flag. * * @return * the SchemaContainsErrors flag */ public boolean isSchemaContainsErrors() { return schemaContainsErrors; } /** * Gets the DependenciesComputer. * * @return * the DependenciesComputer */ public DependenciesComputer getDependenciesComputer() { return dependenciesComputer; } }
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/wizards/ImportSchemasFromOpenLdapWizardPage.java
plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/wizards/ImportSchemasFromOpenLdapWizardPage.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.wizards; import java.io.File; import java.util.ArrayList; import java.util.List; import org.apache.directory.studio.schemaeditor.Activator; import org.apache.directory.studio.schemaeditor.PluginConstants; import org.eclipse.jface.viewers.ArrayContentProvider; import org.eclipse.jface.viewers.CheckStateChangedEvent; import org.eclipse.jface.viewers.CheckboxTableViewer; import org.eclipse.jface.viewers.ICheckStateListener; import org.eclipse.jface.viewers.LabelProvider; 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.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.DirectoryDialog; import org.eclipse.swt.widgets.Group; import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Table; import org.eclipse.swt.widgets.Text; import org.eclipse.ui.PlatformUI; /** * This class represents the WizardPage of the ImportSchemasFromOpenLdapWizard. * <p> * It is used to let the user enter the informations about the * schemas he wants to import. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class ImportSchemasFromOpenLdapWizardPage extends AbstractWizardPage { // UI Fields private Text fromDirectoryText; private Button fromDirectoryButton; private CheckboxTableViewer schemaFilesTableViewer; private Button schemaFilesTableSelectAllButton; private Button schemaFilesTableDeselectAllButton; /** * Creates a new instance of ImportSchemasFromOpenLdapWizardPage. */ protected ImportSchemasFromOpenLdapWizardPage() { super( "ImportSchemasFromOpenLdapWizardPage" ); //$NON-NLS-1$ setTitle( Messages.getString( "ImportSchemasFromOpenLdapWizardPage.ImportSchemaFromOpenLDAP" ) ); //$NON-NLS-1$ setDescription( Messages.getString( "ImportSchemasFromOpenLdapWizardPage.SelectOpenLDAPSchema" ) ); //$NON-NLS-1$ setImageDescriptor( Activator.getDefault().getImageDescriptor( PluginConstants.IMG_SCHEMAS_IMPORT_WIZARD ) ); } /** * {@inheritDoc} */ public void createControl( Composite parent ) { Composite composite = new Composite( parent, SWT.NULL ); GridLayout layout = new GridLayout(); composite.setLayout( layout ); // From Directory Group Group fromDirectoryGroup = new Group( composite, SWT.NONE ); fromDirectoryGroup.setText( Messages.getString( "ImportSchemasFromOpenLdapWizardPage.FromDirectory" ) ); //$NON-NLS-1$ fromDirectoryGroup.setLayout( new GridLayout( 3, false ) ); fromDirectoryGroup.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) ); // From Directory Label fromDirectoryLabel = new Label( fromDirectoryGroup, SWT.NONE ); fromDirectoryLabel.setText( Messages.getString( "ImportSchemasFromOpenLdapWizardPage.FromDirectoryColon" ) ); //$NON-NLS-1$ fromDirectoryText = new Text( fromDirectoryGroup, SWT.BORDER ); fromDirectoryText.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) ); fromDirectoryText.addModifyListener( new ModifyListener() { public void modifyText( ModifyEvent e ) { dialogChanged(); } } ); fromDirectoryButton = new Button( fromDirectoryGroup, SWT.PUSH ); fromDirectoryButton.setText( Messages.getString( "ImportSchemasFromOpenLdapWizardPage.Browse" ) ); //$NON-NLS-1$ fromDirectoryButton.addSelectionListener( new SelectionAdapter() { public void widgetSelected( SelectionEvent e ) { chooseFromDirectory(); } } ); // Schema Files Group Group schemaFilesGroup = new Group( composite, SWT.NONE ); schemaFilesGroup.setText( Messages.getString( "ImportSchemasFromOpenLdapWizardPage.SchemaFiles" ) ); //$NON-NLS-1$ schemaFilesGroup.setLayout( new GridLayout( 2, false ) ); schemaFilesGroup.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) ); // Schema Files schemaFilesTableViewer = new CheckboxTableViewer( new Table( schemaFilesGroup, SWT.BORDER | SWT.CHECK | SWT.FULL_SELECTION ) ); GridData schemasTableViewerGridData = new GridData( SWT.FILL, SWT.NONE, true, false, 1, 2 ); schemasTableViewerGridData.heightHint = 125; schemaFilesTableViewer.getTable().setLayoutData( schemasTableViewerGridData ); schemaFilesTableViewer.setContentProvider( new ArrayContentProvider() ); schemaFilesTableViewer.setLabelProvider( new LabelProvider() { public String getText( Object element ) { if ( element instanceof File ) { return ( ( File ) element ).getName(); } // Default return super.getText( element ); } public Image getImage( Object element ) { if ( element instanceof File ) { return Activator.getDefault().getImage( PluginConstants.IMG_SCHEMA ); } // Default return super.getImage( element ); } } ); schemaFilesTableViewer.addCheckStateListener( new ICheckStateListener() { /** * Notifies of a change to the checked state of an element. * * @param event * event object describing the change */ public void checkStateChanged( CheckStateChangedEvent event ) { dialogChanged(); } } ); schemaFilesTableSelectAllButton = new Button( schemaFilesGroup, SWT.PUSH ); schemaFilesTableSelectAllButton.setText( Messages.getString( "ImportSchemasFromOpenLdapWizardPage.SelectAll" ) ); //$NON-NLS-1$ schemaFilesTableSelectAllButton.setLayoutData( new GridData( SWT.FILL, SWT.BEGINNING, false, false ) ); schemaFilesTableSelectAllButton.addSelectionListener( new SelectionAdapter() { public void widgetSelected( SelectionEvent e ) { schemaFilesTableViewer.setAllChecked( true ); dialogChanged(); } } ); schemaFilesTableDeselectAllButton = new Button( schemaFilesGroup, SWT.PUSH ); schemaFilesTableDeselectAllButton.setText( Messages .getString( "ImportSchemasFromOpenLdapWizardPage.DeselectAll" ) ); //$NON-NLS-1$ schemaFilesTableDeselectAllButton.setLayoutData( new GridData( SWT.FILL, SWT.BEGINNING, false, false ) ); schemaFilesTableDeselectAllButton.addSelectionListener( new SelectionAdapter() { public void widgetSelected( SelectionEvent e ) { schemaFilesTableViewer.setAllChecked( false ); dialogChanged(); } } ); initFields(); dialogChanged(); setControl( composite ); } /** * Initializes the UI Fields. */ private void initFields() { displayErrorMessage( null ); setPageComplete( false ); } /** * This method is called when the exportMultipleFiles 'browse' button is selected. */ private void chooseFromDirectory() { DirectoryDialog dialog = new DirectoryDialog( PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell() ); dialog.setText( Messages.getString( "ImportSchemasFromOpenLdapWizardPage.ChooseFolder" ) ); //$NON-NLS-1$ dialog.setMessage( Messages.getString( "ImportSchemasFromOpenLdapWizardPage.SelectFolderToImportFrom" ) ); //$NON-NLS-1$ if ( "".equals( fromDirectoryText.getText() ) ) //$NON-NLS-1$ { dialog.setFilterPath( Activator.getDefault().getPreferenceStore().getString( PluginConstants.FILE_DIALOG_IMPORT_SCHEMAS_OPENLDAP ) ); } else { dialog.setFilterPath( fromDirectoryText.getText() ); } String selectedDirectory = dialog.open(); if ( selectedDirectory != null ) { fromDirectoryText.setText( selectedDirectory ); fillInSchemaFilesTable( selectedDirectory ); } } /** * Fills in the SchemaFilesTable with the schema files found in the given path. * * @param path * the path to search schema files in */ private void fillInSchemaFilesTable( String path ) { List<File> schemaFiles = new ArrayList<File>(); File selectedDirectory = new File( path ); if ( selectedDirectory.exists() ) { for ( File file : selectedDirectory.listFiles() ) { String fileName = file.getName(); if ( fileName.endsWith( ".schema" ) ) //$NON-NLS-1$ { schemaFiles.add( file ); } } } schemaFilesTableViewer.setInput( schemaFiles ); } /** * This method is called when the user modifies something in the UI. */ private void dialogChanged() { // Checking if a Schema Project is open if ( Activator.getDefault().getSchemaHandler() == null ) { displayErrorMessage( Messages.getString( "ImportSchemasFromOpenLdapWizardPage.ErrorNotSchemaProjectOpen" ) ); //$NON-NLS-1$ return; } // Import Directory String directory = fromDirectoryText.getText(); if ( ( directory == null ) || ( directory.equals( "" ) ) ) //$NON-NLS-1$ { displayErrorMessage( Messages.getString( "ImportSchemasFromOpenLdapWizardPage.ErrorNoDirectorySelected" ) ); //$NON-NLS-1$ return; } else { File directoryFile = new File( directory ); if ( !directoryFile.exists() ) { displayErrorMessage( Messages .getString( "ImportSchemasFromOpenLdapWizardPage.ErrorSelectedDirectoryNotExists" ) ); //$NON-NLS-1$ return; } else if ( !directoryFile.isDirectory() ) { displayErrorMessage( Messages .getString( "ImportSchemasFromOpenLdapWizardPage.ErrorSelectedDirectoryNotDirectory" ) ); //$NON-NLS-1$ return; } else if ( !directoryFile.canRead() ) { displayErrorMessage( Messages .getString( "ImportSchemasFromOpenLdapWizardPage.ErrorSelectedDirectoryNotReadable" ) ); //$NON-NLS-1$ return; } } // Schemas table if ( schemaFilesTableViewer.getCheckedElements().length == 0 ) { displayErrorMessage( Messages.getString( "ImportSchemasFromOpenLdapWizardPage.ErrorNoSchemaSelected" ) ); //$NON-NLS-1$ return; } displayErrorMessage( null ); } /** * Gets the selected schema files. * * @return * the selected schema files */ public File[] getSelectedSchemaFiles() { Object[] selectedSchemaFile = schemaFilesTableViewer.getCheckedElements(); List<File> schemaFiles = new ArrayList<File>(); for ( Object schemaFile : selectedSchemaFile ) { schemaFiles.add( ( File ) schemaFile ); } return schemaFiles.toArray( new File[0] ); } /** * Saves the dialog settings. */ public void saveDialogSettings() { Activator.getDefault().getPreferenceStore().putValue( PluginConstants.FILE_DIALOG_IMPORT_SCHEMAS_OPENLDAP, fromDirectoryText.getText() ); } }
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/wizards/NewObjectClassGeneralPageWizardPage.java
plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/wizards/NewObjectClassGeneralPageWizardPage.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.wizards; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.List; import org.apache.directory.api.asn1.util.Oid; 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.model.Schema; import org.apache.directory.studio.schemaeditor.model.alias.Alias; import org.apache.directory.studio.schemaeditor.model.alias.AliasWithPartError; import org.apache.directory.studio.schemaeditor.model.alias.AliasWithStartError; import org.apache.directory.studio.schemaeditor.model.alias.AliasesStringParser; import org.apache.directory.studio.schemaeditor.view.dialogs.EditObjectClassAliasesDialog; import org.eclipse.jface.viewers.ArrayContentProvider; import org.eclipse.jface.viewers.ComboViewer; import org.eclipse.jface.viewers.ISelectionChangedListener; import org.eclipse.jface.viewers.LabelProvider; import org.eclipse.jface.viewers.SelectionChangedEvent; import org.eclipse.jface.viewers.StructuredSelection; import org.eclipse.osgi.util.NLS; 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.Group; import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Text; /** * This class represents the General WizardPage of the NewObjectClassWizard. * <p> * It is used to let the user enter general information about the * attribute type he wants to create (schema, OID, aliases an description). * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class NewObjectClassGeneralPageWizardPage extends AbstractWizardPage { /** The SchemaHandler */ private SchemaHandler schemaHandler; /** The aliases */ private List<Alias> aliases; /** The selected schema */ private Schema selectedSchema; // UI fields private ComboViewer schemaComboViewer; private Combo oidCombo; private Text aliasesText; private Button aliasesButton; private Text descriptionText; /** * Creates a new instance of NewObjectClassGeneralPageWizardPage. */ protected NewObjectClassGeneralPageWizardPage() { super( "NewObjectClassGeneralPageWizardPage" ); //$NON-NLS-1$ setTitle( Messages.getString( "NewObjectClassGeneralPageWizardPage.ObjectClass" ) ); //$NON-NLS-1$ setDescription( Messages.getString( "NewObjectClassGeneralPageWizardPage.CreateObjectClass" ) ); //$NON-NLS-1$ setImageDescriptor( Activator.getDefault().getImageDescriptor( PluginConstants.IMG_OBJECT_CLASS_NEW_WIZARD ) ); schemaHandler = Activator.getDefault().getSchemaHandler(); aliases = new ArrayList<Alias>(); } /** * {@inheritDoc} */ public void createControl( Composite parent ) { Composite composite = new Composite( parent, SWT.NULL ); GridLayout layout = new GridLayout(); composite.setLayout( layout ); // Schema Group Group schemaGroup = new Group( composite, SWT.NONE ); schemaGroup.setText( Messages.getString( "NewObjectClassGeneralPageWizardPage.Schema" ) ); //$NON-NLS-1$ schemaGroup.setLayout( new GridLayout( 2, false ) ); schemaGroup.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) ); // Schema Label schemaLabel = new Label( schemaGroup, SWT.NONE ); schemaLabel.setText( Messages.getString( "NewObjectClassGeneralPageWizardPage.SchemaColon" ) ); //$NON-NLS-1$ Combo schemaCombo = new Combo( schemaGroup, SWT.READ_ONLY ); schemaCombo.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) ); schemaComboViewer = new ComboViewer( schemaCombo ); schemaComboViewer.setContentProvider( new ArrayContentProvider() ); schemaComboViewer.setLabelProvider( new LabelProvider() { /** * {@inheritDoc} */ public String getText( Object element ) { if ( element instanceof Schema ) { return ( ( Schema ) element ).getSchemaName(); } // Default return super.getText( element ); } } ); schemaComboViewer.addSelectionChangedListener( new ISelectionChangedListener() { /** * {@inheritDoc} */ public void selectionChanged( SelectionChangedEvent event ) { dialogChanged(); } } ); // Naming and Description Group Group namingDescriptionGroup = new Group( composite, SWT.NONE ); namingDescriptionGroup .setText( Messages.getString( "NewObjectClassGeneralPageWizardPage.NamingAndDescription" ) ); //$NON-NLS-1$ namingDescriptionGroup.setLayout( new GridLayout( 3, false ) ); namingDescriptionGroup.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) ); // OID Label oidLabel = new Label( namingDescriptionGroup, SWT.NONE ); oidLabel.setText( Messages.getString( "NewObjectClassGeneralPageWizardPage.OID" ) ); //$NON-NLS-1$ oidCombo = new Combo( namingDescriptionGroup, SWT.DROP_DOWN | SWT.BORDER ); oidCombo.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false, 2, 1 ) ); oidCombo.addModifyListener( new ModifyListener() { /** * {@inheritDoc} */ public void modifyText( ModifyEvent arg0 ) { dialogChanged(); } } ); oidCombo.addVerifyListener( new VerifyListener() { /** * {@inheritDoc} */ public void verifyText( VerifyEvent e ) { if ( !e.text.matches( "([0-9]*\\.?)*" ) ) //$NON-NLS-1$ { e.doit = false; } } } ); oidCombo.setItems( PluginUtils.loadDialogSettingsHistory( PluginConstants.DIALOG_SETTINGS_OID_HISTORY ) ); // Aliases Label aliasesLabel = new Label( namingDescriptionGroup, SWT.NONE ); aliasesLabel.setText( Messages.getString( "NewObjectClassGeneralPageWizardPage.Aliases" ) ); //$NON-NLS-1$ aliasesText = new Text( namingDescriptionGroup, SWT.BORDER ); aliasesText.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) ); aliasesText.addModifyListener( new ModifyListener() { public void modifyText( ModifyEvent e ) { AliasesStringParser parser = new AliasesStringParser(); parser.parse( aliasesText.getText() ); List<Alias> parsedAliases = parser.getAliases(); aliases.clear(); for ( Alias parsedAlias : parsedAliases ) { aliases.add( parsedAlias ); } dialogChanged(); } } ); aliasesButton = new Button( namingDescriptionGroup, SWT.PUSH ); aliasesButton.setText( Messages.getString( "NewObjectClassGeneralPageWizardPage.Edit" ) ); //$NON-NLS-1$ aliasesButton.addSelectionListener( new SelectionAdapter() { /** * {@inheritDoc} */ public void widgetSelected( SelectionEvent arg0 ) { EditObjectClassAliasesDialog dialog = new EditObjectClassAliasesDialog( getAliasesValue() ); if ( dialog.open() == EditObjectClassAliasesDialog.OK ) { String[] newAliases = dialog.getAliases(); StringBuffer sb = new StringBuffer(); for ( String newAlias : newAliases ) { sb.append( newAlias ); sb.append( ", " ); //$NON-NLS-1$ } sb.deleteCharAt( sb.length() - 1 ); sb.deleteCharAt( sb.length() - 1 ); AliasesStringParser parser = new AliasesStringParser(); parser.parse( sb.toString() ); List<Alias> parsedAliases = parser.getAliases(); aliases.clear(); for ( Alias parsedAlias : parsedAliases ) { aliases.add( parsedAlias ); } fillInAliasesLabel(); dialogChanged(); } } } ); // Description Label descriptionLabel = new Label( namingDescriptionGroup, SWT.NONE ); descriptionLabel.setText( Messages.getString( "NewObjectClassGeneralPageWizardPage.Description" ) ); //$NON-NLS-1$ descriptionText = new Text( namingDescriptionGroup, SWT.MULTI | SWT.BORDER | SWT.V_SCROLL ); GridData descriptionGridData = new GridData( SWT.FILL, SWT.NONE, true, false, 2, 1 ); descriptionGridData.heightHint = 67; descriptionText.setLayoutData( descriptionGridData ); descriptionText.addModifyListener( new ModifyListener() { /** * {@inheritDoc} */ public void modifyText( ModifyEvent arg0 ) { dialogChanged(); } } ); initFields(); setControl( composite ); } /** * Initializes the UI fields. */ private void initFields() { if ( schemaHandler == null ) { schemaComboViewer.getCombo().setEnabled( false ); oidCombo.setEnabled( false ); aliasesText.setEnabled( false ); aliasesButton.setEnabled( false ); descriptionText.setEnabled( false ); displayErrorMessage( Messages.getString( "NewObjectClassGeneralPageWizardPage.ErrorNoSchemaProjectOpen" ) ); //$NON-NLS-1$ } else { // Filling the Schemas table List<Schema> schemas = new ArrayList<Schema>(); schemas.addAll( schemaHandler.getSchemas() ); Collections.sort( schemas, new Comparator<Schema>() { public int compare( Schema o1, Schema o2 ) { return o1.getSchemaName().compareToIgnoreCase( o2.getSchemaName() ); } } ); schemaComboViewer.setInput( schemas ); if ( selectedSchema != null ) { schemaComboViewer.setSelection( new StructuredSelection( selectedSchema ) ); } displayErrorMessage( null ); } setPageComplete( false ); } /** * This method is called when the user modifies something in the UI. */ private void dialogChanged() { if ( schemaComboViewer.getSelection().isEmpty() ) { displayErrorMessage( Messages.getString( "NewObjectClassGeneralPageWizardPage.ErrorNoSchemaSpecified" ) ); //$NON-NLS-1$ return; } if ( oidCombo.getText().equals( "" ) ) //$NON-NLS-1$ { displayErrorMessage( Messages.getString( "NewObjectClassGeneralPageWizardPage.ErrorNoOIDSpecified" ) ); //$NON-NLS-1$ return; } if ( ( !oidCombo.getText().equals( "" ) ) && ( !Oid.isOid( oidCombo.getText() ) ) ) //$NON-NLS-1$ { displayErrorMessage( Messages.getString( "NewObjectClassGeneralPageWizardPage.ErrorIncorrectOID" ) ); //$NON-NLS-1$ return; } if ( ( !oidCombo.getText().equals( "" ) ) && ( Oid.isOid( oidCombo.getText() ) ) //$NON-NLS-1$ && ( schemaHandler.isOidAlreadyTaken( oidCombo.getText() ) ) ) { displayErrorMessage( Messages.getString( "NewObjectClassGeneralPageWizardPage.ErrorObjectOIDExists" ) ); //$NON-NLS-1$ return; } if ( aliases.size() == 0 ) { displayWarningMessage( Messages.getString( "NewObjectClassGeneralPageWizardPage.ErrorObjectClassNoName" ) ); //$NON-NLS-1$ return; } else { for ( Alias alias : aliases ) { if ( alias instanceof AliasWithStartError ) { displayErrorMessage( NLS .bind( Messages.getString( "NewObjectClassGeneralPageWizardPage.AliasStartInvalid" ), new Object[] { alias, ( ( AliasWithStartError ) alias ).getErrorChar() } ) ); //$NON-NLS-1$ return; } else if ( alias instanceof AliasWithPartError ) { displayErrorMessage( NLS .bind( Messages.getString( "NewObjectClassGeneralPageWizardPage.AliasPartInvalid" ), new Object[] { alias, ( ( AliasWithPartError ) alias ).getErrorChar() } ) ); //$NON-NLS-1$ return; } } } displayErrorMessage( null ); } /** * Fills in the Aliases Label. */ private void fillInAliasesLabel() { StringBuffer sb = new StringBuffer(); for ( Alias alias : aliases ) { sb.append( alias ); sb.append( ", " ); //$NON-NLS-1$ } sb.deleteCharAt( sb.length() - 1 ); sb.deleteCharAt( sb.length() - 1 ); aliasesText.setText( sb.toString() ); } /** * Get the name of the schema. * * @return * the name of the schema */ public String getSchemaValue() { StructuredSelection selection = ( StructuredSelection ) schemaComboViewer.getSelection(); if ( !selection.isEmpty() ) { Schema schema = ( Schema ) selection.getFirstElement(); return schema.getSchemaName(); } else { return null; } } /** * Gets the value of the OID. * * @return * the value of the OID */ public String getOidValue() { return oidCombo.getText(); } /** * Gets the value of the aliases. * * @return * the value of the aliases */ public List<String> getAliasesValue() { List<String> aliasesValue = new ArrayList<String>(); for ( Alias alias : aliases ) { aliasesValue.add( alias.toString() ); } return aliasesValue; } /** * Gets the value of the description. * * @return * the value of the description */ public String getDescriptionValue() { return descriptionText.getText(); } /** * Sets the selected schema. * * @param schema * the selected schema */ public void setSelectedSchema( Schema schema ) { selectedSchema = 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/wizards/CommitChangesDifferencesWizardPage.java
plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/wizards/CommitChangesDifferencesWizardPage.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.wizards; 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.difference.DifferenceEngine; import org.apache.directory.studio.schemaeditor.view.widget.DifferencesWidget; import org.eclipse.jface.wizard.WizardPage; import org.eclipse.swt.SWT; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Composite; /** * This class represents the WizardPage of the ExportProjectsWizard. * <p> * It is used to let the user enter the informations about the * schemas projects he wants to export and where to export. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class CommitChangesDifferencesWizardPage extends WizardPage { // UI Fields private DifferencesWidget differencesWidget; /** * Creates a new instance of ExportSchemasAsXmlWizardPage. */ protected CommitChangesDifferencesWizardPage() { super( "CommitChangesDifferencesWizardPage" ); //$NON-NLS-1$ setTitle( Messages.getString( "CommitChangesDifferencesWizardPage.CommitChanges" ) ); //$NON-NLS-1$ setDescription( Messages.getString( "CommitChangesDifferencesWizardPage.DisplayModifications" ) ); //$NON-NLS-1$ setImageDescriptor( Activator.getDefault().getImageDescriptor( PluginConstants.IMG_COMMIT_CHANGES_WIZARD ) ); } /** * {@inheritDoc} */ public void createControl( Composite parent ) { Composite composite = new Composite( parent, SWT.NULL ); GridLayout layout = new GridLayout(); composite.setLayout( layout ); differencesWidget = new DifferencesWidget(); differencesWidget.createWidget( composite ); initFields(); setControl( composite ); } /** * Initializes the UI Fields. */ private void initFields() { Project project = Activator.getDefault().getProjectsHandler().getOpenProject(); differencesWidget.setInput( DifferenceEngine.getDifferences( project.getInitialSchema(), project .getSchemaHandler().getSchemas() ) ); } /** * {@inheritDoc} */ public void dispose() { differencesWidget.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/wizards/CommitChangesInformationWizardPage.java
plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/wizards/CommitChangesInformationWizardPage.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.wizards; import org.apache.directory.studio.schemaeditor.Activator; import org.apache.directory.studio.schemaeditor.PluginConstants; import org.eclipse.jface.wizard.WizardPage; 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; /** * This class represents the InformationWizardPage of the CommitChangesWizard. * <p> * It is used to let the user enter the informations about the * schemas projects he wants to export and where to export. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class CommitChangesInformationWizardPage extends WizardPage { // UI Fields /** * Creates a new instance of ExportSchemasAsXmlWizardPage. */ protected CommitChangesInformationWizardPage() { super( "CommitChangesInformationWizardPage" ); //$NON-NLS-1$ setTitle( Messages.getString( "CommitChangesInformationWizardPage.CommitChanges" ) ); //$NON-NLS-1$ setDescription( Messages.getString( "CommitChangesInformationWizardPage.PleaseReadInformationBeforeCommitting" ) ); //$NON-NLS-1$ setImageDescriptor( Activator.getDefault().getImageDescriptor( PluginConstants.IMG_COMMIT_CHANGES_WIZARD ) ); } /** * {@inheritDoc} */ public void createControl( Composite parent ) { Composite composite = new Composite( parent, SWT.NULL ); GridLayout layout = new GridLayout(); composite.setLayout( layout ); composite.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) ); // Information Label String informationString = Messages.getString( "CommitChangesInformationWizardPage.YouAreAboutToCommit" ); //$NON-NLS-1$ Label informationLabel = new Label( composite, SWT.WRAP ); informationLabel.setText( informationString ); informationLabel.setLayoutData( new GridData( SWT.FILL, SWT.CENTER, true, true ) ); // Warning Label Label warningLabel = new Label( composite, SWT.NONE ); warningLabel.setImage( Activator.getDefault().getImage( PluginConstants.IMG_WARNING_32X32 ) ); warningLabel.setLayoutData( new GridData( SWT.CENTER, SWT.BOTTOM, true, true ) ); setControl( composite ); } }
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/wizards/ExportProjectsWizard.java
plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/wizards/ExportProjectsWizard.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.wizards; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.UnsupportedEncodingException; import java.lang.reflect.InvocationTargetException; import org.apache.directory.studio.schemaeditor.PluginUtils; import org.apache.directory.studio.schemaeditor.model.Project; import org.apache.directory.studio.schemaeditor.model.io.ProjectsExporter; import org.apache.directory.studio.schemaeditor.view.ViewUtils; import org.dom4j.io.OutputFormat; import org.dom4j.io.XMLWriter; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.jface.operation.IRunnableWithProgress; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jface.wizard.Wizard; import org.eclipse.osgi.util.NLS; import org.eclipse.ui.IExportWizard; import org.eclipse.ui.IWorkbench; /** * This class represents the wizard to export schema projects. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class ExportProjectsWizard extends Wizard implements IExportWizard { /** The selected projects */ private Project[] selectedProjects = new Project[0]; // The pages of the wizard private ExportProjectsWizardPage page; /** * {@inheritDoc} */ public void addPages() { // Creating pages page = new ExportProjectsWizardPage(); page.setSelectedProjects( selectedProjects ); // Adding pages addPage( page ); } /** * {@inheritDoc} */ public boolean performFinish() { // Saving the dialog settings page.saveDialogSettings(); // Getting the projects to be exported and where to export them final Project[] selectedProjects = page.getSelectedProjects(); final String exportDirectory = page.getExportDirectory(); try { getContainer().run( false, false, new IRunnableWithProgress() { public void run( IProgressMonitor monitor ) { monitor.beginTask( Messages.getString( "ExportProjectsWizard.ExportingProject" ), selectedProjects.length ); //$NON-NLS-1$ for ( Project project : selectedProjects ) { monitor.subTask( project.getName() ); try { OutputFormat outformat = OutputFormat.createPrettyPrint(); outformat.setEncoding( "UTF-8" ); //$NON-NLS-1$ XMLWriter writer = new XMLWriter( new FileOutputStream( exportDirectory + "/" //$NON-NLS-1$ + project.getName() + ".schemaproject" ), outformat ); //$NON-NLS-1$ writer.write( ProjectsExporter.toDocument( project ) ); writer.flush(); } catch ( UnsupportedEncodingException e ) { PluginUtils .logError( NLS .bind( Messages.getString( "ExportProjectsWizard.ErrorWhenSavingProject" ), new String[] { project.getName() } ), e ); //$NON-NLS-1$ ViewUtils .displayErrorMessageDialog( Messages.getString( "ExportProjectsWizard.Error" ), NLS.bind( Messages.getString( "ExportProjectsWizard.ErrorWhenSavingProject" ), new String[] { project.getName() } ) ); //$NON-NLS-1$ //$NON-NLS-2$ } catch ( FileNotFoundException e ) { PluginUtils .logError( NLS .bind( Messages.getString( "ExportProjectsWizard.ErrorWhenSavingProject" ), new String[] { project.getName() } ), e ); //$NON-NLS-1$ ViewUtils .displayErrorMessageDialog( Messages.getString( "ExportProjectsWizard.Error" ), NLS.bind( Messages.getString( "ExportProjectsWizard.ErrorWhenSavingProject" ), new String[] { project.getName() } ) ); //$NON-NLS-1$ //$NON-NLS-2$ } catch ( IOException e ) { PluginUtils .logError( NLS .bind( Messages.getString( "ExportProjectsWizard.ErrorWhenSavingProject" ), new String[] { project.getName() } ), e ); //$NON-NLS-1$ ViewUtils .displayErrorMessageDialog( Messages.getString( "ExportProjectsWizard.Error" ), NLS.bind( Messages.getString( "ExportProjectsWizard.ErrorWhenSavingProject" ), new String[] { project.getName() } ) ); //$NON-NLS-1$ //$NON-NLS-2$ } monitor.worked( 1 ); } monitor.done(); } } ); } catch ( InvocationTargetException e ) { // Nothing to do (it will never occur) } catch ( InterruptedException e ) { // Nothing to do. } return true; } /** * Sets the selected projects. * * @param projects * the projects */ public void setSelectedProjects( Project[] projects ) { selectedProjects = projects; } /** * {@inheritDoc} */ public void init( IWorkbench workbench, IStructuredSelection 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/wizards/Messages.java
plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/wizards/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.wizards; 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/wizards/AbstractWizardPage.java
plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/wizards/AbstractWizardPage.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.wizards; import org.eclipse.jface.dialogs.DialogPage; import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.jface.wizard.WizardPage; /** * This abstract class extends {@link WizardPage} and holds common methods * for all our {@link WizardPage}s. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public abstract class AbstractWizardPage extends WizardPage { /** * Creates a new wizard page with the given name, title, and image. * * @param pageName the name of the page * @param title the title for this wizard page, * or <code>null</code> if none * @param titleImage the image descriptor for the title of this wizard page, * or <code>null</code> if none */ protected AbstractWizardPage( String pageName, String title, ImageDescriptor titleImage ) { super( pageName, title, titleImage ); } /** * Creates a new wizard page with the given name, and * with no title or image. * * @param pageName the name of the page */ protected AbstractWizardPage( String pageName ) { super( pageName ); } /** * Displays an error message and set the page status as incomplete * if the message is not null. * * @param message * the message to display */ protected void displayErrorMessage( String message ) { setMessage( null, DialogPage.NONE ); setErrorMessage( message ); setPageComplete( message == null ); } /** * Displays a warning message and set the page status as complete. * * @param message * the message to display */ protected void displayWarningMessage( String message ) { setErrorMessage( null ); setMessage( message, DialogPage.WARNING ); setPageComplete( 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/wizards/ExportSchemasAsXmlWizardPage.java
plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/wizards/ExportSchemasAsXmlWizardPage.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.wizards; import java.io.File; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.List; 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.eclipse.jface.viewers.ArrayContentProvider; import org.eclipse.jface.viewers.CheckStateChangedEvent; import org.eclipse.jface.viewers.CheckboxTableViewer; import org.eclipse.jface.viewers.ICheckStateListener; import org.eclipse.jface.viewers.LabelProvider; 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.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.DirectoryDialog; import org.eclipse.swt.widgets.FileDialog; import org.eclipse.swt.widgets.Group; import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Table; import org.eclipse.swt.widgets.Text; import org.eclipse.ui.PlatformUI; /** * This class represents the WizardPage of the ExportSchemasAsXmlWizard. * <p> * It is used to let the user enter the informations about the * schemas he wants to export and where to export. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class ExportSchemasAsXmlWizardPage extends AbstractWizardPage { /** The selected schemas */ private Schema[] selectedSchemas = new Schema[0]; /** The SchemaHandler */ private SchemaHandler schemaHandler; public static final int EXPORT_MULTIPLE_FILES = 0; public static final int EXPORT_SINGLE_FILE = 1; // UI Fields private CheckboxTableViewer schemasTableViewer; private Button schemasTableSelectAllButton; private Button schemasTableDeselectAllButton; private Button exportMultipleFilesRadio; private Label exportMultipleFilesLabel; private Text exportMultipleFilesText; private Button exportMultipleFilesButton; private Button exportSingleFileRadio; private Label exportSingleFileLabel; private Text exportSingleFileText; private Button exportSingleFileButton; /** * Creates a new instance of ExportSchemasAsXmlWizardPage. */ protected ExportSchemasAsXmlWizardPage() { super( "ExportSchemasAsXmlWizardPage" ); //$NON-NLS-1$ setTitle( Messages.getString( "ExportSchemasAsXmlWizardPage.ExportSchemaAsXML" ) ); //$NON-NLS-1$ setDescription( Messages.getString( "ExportSchemasAsXmlWizardPage.PleaseSelectSchemas" ) ); //$NON-NLS-1$ setImageDescriptor( Activator.getDefault().getImageDescriptor( PluginConstants.IMG_SCHEMAS_EXPORT_WIZARD ) ); schemaHandler = Activator.getDefault().getSchemaHandler(); } /** * {@inheritDoc} */ public void createControl( Composite parent ) { Composite composite = new Composite( parent, SWT.NULL ); GridLayout layout = new GridLayout(); composite.setLayout( layout ); // Schemas Group Group schemasGroup = new Group( composite, SWT.NONE ); schemasGroup.setText( Messages.getString( "ExportSchemasAsXmlWizardPage.Schemas" ) ); //$NON-NLS-1$ schemasGroup.setLayout( new GridLayout( 2, false ) ); schemasGroup.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) ); // Schemas TableViewer Label schemasLabel = new Label( schemasGroup, SWT.NONE ); schemasLabel.setText( Messages.getString( "ExportSchemasAsXmlWizardPage.SelectSchemasToExport" ) ); //$NON-NLS-1$ schemasLabel.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false, 2, 1 ) ); schemasTableViewer = new CheckboxTableViewer( new Table( schemasGroup, SWT.BORDER | SWT.CHECK | SWT.FULL_SELECTION ) ); GridData schemasTableViewerGridData = new GridData( SWT.FILL, SWT.NONE, true, false, 1, 2 ); schemasTableViewerGridData.heightHint = 125; schemasTableViewer.getTable().setLayoutData( schemasTableViewerGridData ); schemasTableViewer.setContentProvider( new ArrayContentProvider() ); schemasTableViewer.setLabelProvider( new LabelProvider() { public String getText( Object element ) { if ( element instanceof Schema ) { return ( ( Schema ) element ).getSchemaName(); } // Default return super.getText( element ); } public Image getImage( Object element ) { if ( element instanceof Schema ) { return Activator.getDefault().getImage( PluginConstants.IMG_SCHEMA ); } // Default return super.getImage( element ); } } ); schemasTableViewer.addCheckStateListener( new ICheckStateListener() { /** * Notifies of a change to the checked state of an element. * * @param event * event object describing the change */ public void checkStateChanged( CheckStateChangedEvent event ) { dialogChanged(); } } ); schemasTableSelectAllButton = new Button( schemasGroup, SWT.PUSH ); schemasTableSelectAllButton.setText( Messages.getString( "ExportSchemasAsXmlWizardPage.SelectAll" ) ); //$NON-NLS-1$ schemasTableSelectAllButton.setLayoutData( new GridData( SWT.FILL, SWT.BEGINNING, false, false ) ); schemasTableSelectAllButton.addSelectionListener( new SelectionAdapter() { public void widgetSelected( SelectionEvent e ) { schemasTableViewer.setAllChecked( true ); dialogChanged(); } } ); schemasTableDeselectAllButton = new Button( schemasGroup, SWT.PUSH ); schemasTableDeselectAllButton.setText( Messages.getString( "ExportSchemasAsXmlWizardPage.DeselectAll" ) ); //$NON-NLS-1$ schemasTableDeselectAllButton.setLayoutData( new GridData( SWT.FILL, SWT.BEGINNING, false, false ) ); schemasTableDeselectAllButton.addSelectionListener( new SelectionAdapter() { public void widgetSelected( SelectionEvent e ) { schemasTableViewer.setAllChecked( false ); dialogChanged(); } } ); // Export Destination Group Group exportDestinationGroup = new Group( composite, SWT.NULL ); exportDestinationGroup.setText( Messages.getString( "ExportSchemasAsXmlWizardPage.ExportDdestination" ) ); //$NON-NLS-1$ exportDestinationGroup.setLayout( new GridLayout( 4, false ) ); exportDestinationGroup.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) ); // Export Multiple Files exportMultipleFilesRadio = new Button( exportDestinationGroup, SWT.RADIO ); exportMultipleFilesRadio.setText( Messages .getString( "ExportSchemasAsXmlWizardPage.ExportEachSchemaAsSeparateFile" ) ); //$NON-NLS-1$ exportMultipleFilesRadio.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false, 4, 1 ) ); exportMultipleFilesRadio.addSelectionListener( new SelectionAdapter() { public void widgetSelected( SelectionEvent e ) { exportMultipleFilesSelected(); dialogChanged(); } } ); Label exportMultipleFilesFiller = new Label( exportDestinationGroup, SWT.NONE ); exportMultipleFilesFiller.setText( " " ); //$NON-NLS-1$ exportMultipleFilesLabel = new Label( exportDestinationGroup, SWT.NONE ); exportMultipleFilesLabel.setText( Messages.getString( "ExportSchemasAsXmlWizardPage.Directory" ) ); //$NON-NLS-1$ exportMultipleFilesText = new Text( exportDestinationGroup, SWT.BORDER ); exportMultipleFilesText.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) ); exportMultipleFilesText.addModifyListener( new ModifyListener() { public void modifyText( ModifyEvent e ) { dialogChanged(); } } ); exportMultipleFilesButton = new Button( exportDestinationGroup, SWT.PUSH ); exportMultipleFilesButton.setText( Messages.getString( "ExportSchemasAsXmlWizardPage.Browse" ) ); //$NON-NLS-1$ exportMultipleFilesButton.addSelectionListener( new SelectionAdapter() { public void widgetSelected( SelectionEvent e ) { chooseExportDirectory(); dialogChanged(); } } ); // Export Single File exportSingleFileRadio = new Button( exportDestinationGroup, SWT.RADIO ); exportSingleFileRadio.setText( Messages.getString( "ExportSchemasAsXmlWizardPage.ExportSchemaAsSingleFile" ) ); //$NON-NLS-1$ exportSingleFileRadio.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false, 4, 1 ) ); exportSingleFileRadio.addSelectionListener( new SelectionAdapter() { public void widgetSelected( SelectionEvent e ) { exportSingleFileSelected(); dialogChanged(); } } ); Label exportSingleFileFiller = new Label( exportDestinationGroup, SWT.NONE ); exportSingleFileFiller.setText( " " ); //$NON-NLS-1$ exportSingleFileLabel = new Label( exportDestinationGroup, SWT.NONE ); exportSingleFileLabel.setText( Messages.getString( "ExportSchemasAsXmlWizardPage.ExportFile" ) ); //$NON-NLS-1$ exportSingleFileText = new Text( exportDestinationGroup, SWT.BORDER ); exportSingleFileText.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) ); exportSingleFileText.addModifyListener( new ModifyListener() { public void modifyText( ModifyEvent e ) { dialogChanged(); } } ); exportSingleFileButton = new Button( exportDestinationGroup, SWT.PUSH ); exportSingleFileButton.setText( Messages.getString( "ExportSchemasAsXmlWizardPage.Browse" ) ); //$NON-NLS-1$ exportSingleFileButton.addSelectionListener( new SelectionAdapter() { /** * {@inheritDoc} */ public void widgetSelected( SelectionEvent e ) { chooseExportFile(); dialogChanged(); } } ); initFields(); dialogChanged(); setControl( composite ); } /** * Initializes the UI Fields. */ private void initFields() { // Filling the Schemas table if ( schemaHandler != null ) { List<Schema> schemas = new ArrayList<Schema>(); schemas.addAll( schemaHandler.getSchemas() ); Collections.sort( schemas, new Comparator<Schema>() { public int compare( Schema o1, Schema o2 ) { return o1.getSchemaName().compareToIgnoreCase( o2.getSchemaName() ); } } ); schemasTableViewer.setInput( schemas ); // Setting the selected schemas schemasTableViewer.setCheckedElements( selectedSchemas ); } // Selecting the Multiple Files choice exportMultipleFilesSelected(); displayErrorMessage( null ); setPageComplete( false ); } /** * This method is called when the exportMultipleFiles radio button is selected. */ private void exportMultipleFilesSelected() { exportMultipleFilesRadio.setSelection( true ); exportMultipleFilesLabel.setEnabled( true ); exportMultipleFilesText.setEnabled( true ); exportMultipleFilesButton.setEnabled( true ); exportSingleFileRadio.setSelection( false ); exportSingleFileLabel.setEnabled( false ); exportSingleFileText.setEnabled( false ); exportSingleFileButton.setEnabled( false ); } /** * This method is called when the exportSingleFile radio button is selected. */ private void exportSingleFileSelected() { exportMultipleFilesRadio.setSelection( false ); exportMultipleFilesLabel.setEnabled( false ); exportMultipleFilesText.setEnabled( false ); exportMultipleFilesButton.setEnabled( false ); exportSingleFileRadio.setSelection( true ); exportSingleFileLabel.setEnabled( true ); exportSingleFileText.setEnabled( true ); exportSingleFileButton.setEnabled( true ); } /** * This method is called when the exportMultipleFiles 'browse' button is selected. */ private void chooseExportDirectory() { DirectoryDialog dialog = new DirectoryDialog( PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell() ); dialog.setText( Messages.getString( "ExportSchemasAsXmlWizardPage.ChooseFolder" ) ); //$NON-NLS-1$ dialog.setMessage( Messages.getString( "ExportSchemasAsXmlWizardPage.SelectFolderToExport" ) ); //$NON-NLS-1$ if ( "".equals( exportMultipleFilesText.getText() ) ) //$NON-NLS-1$ { dialog.setFilterPath( Activator.getDefault().getPreferenceStore().getString( PluginConstants.FILE_DIALOG_EXPORT_SCHEMAS_XML ) ); } else { dialog.setFilterPath( exportMultipleFilesText.getText() ); } String selectedDirectory = dialog.open(); if ( selectedDirectory != null ) { exportMultipleFilesText.setText( selectedDirectory ); } } /** * This method is called when the exportSingleFile 'browse' button is selected. */ private void chooseExportFile() { FileDialog dialog = new FileDialog( PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), SWT.SAVE ); dialog.setText( Messages.getString( "ExportSchemasAsXmlWizardPage.SelectFile" ) ); //$NON-NLS-1$ dialog.setFilterExtensions( new String[] { "*.xml", "*" } ); //$NON-NLS-1$ //$NON-NLS-2$ dialog .setFilterNames( new String[] { Messages.getString( "ExportSchemasAsXmlWizardPage.XMLFiles" ), Messages.getString( "ExportSchemasAsXmlWizardPage.AllFiles" ) } ); //$NON-NLS-1$ //$NON-NLS-2$ if ( "".equals( exportSingleFileText.getText() ) ) //$NON-NLS-1$ { dialog.setFilterPath( Activator.getDefault().getPreferenceStore().getString( PluginConstants.FILE_DIALOG_EXPORT_SCHEMAS_XML ) ); } else { dialog.setFilterPath( exportSingleFileText.getText() ); } String selectedFile = dialog.open(); if ( selectedFile != null ) { exportSingleFileText.setText( selectedFile ); } } /** * This method is called when the user modifies something in the UI. */ private void dialogChanged() { // Checking if a Schema Project is open if ( schemaHandler == null ) { displayErrorMessage( Messages.getString( "ExportSchemasAsXmlWizardPage.ErrorNoOpenSchemaProject" ) ); //$NON-NLS-1$ return; } // Schemas table if ( schemasTableViewer.getCheckedElements().length == 0 ) { displayErrorMessage( Messages.getString( "ExportSchemasAsXmlWizardPage.ErrorNoSelectedSchema" ) ); //$NON-NLS-1$ return; } // Export option if ( exportMultipleFilesRadio.getSelection() ) { String directory = exportMultipleFilesText.getText(); if ( ( directory == null ) || ( directory.equals( "" ) ) ) //$NON-NLS-1$ { displayErrorMessage( Messages.getString( "ExportSchemasAsXmlWizardPage.ErrorNotSelectedDirectory" ) ); //$NON-NLS-1$ return; } else { File directoryFile = new File( directory ); if ( !directoryFile.exists() ) { displayErrorMessage( Messages .getString( "ExportSchemasAsXmlWizardPage.ErrorSelectedDirectoryNotExists" ) ); //$NON-NLS-1$ return; } else if ( !directoryFile.isDirectory() ) { displayErrorMessage( Messages .getString( "ExportSchemasAsXmlWizardPage.ErrorSelectedDirectoryNotDirectory" ) ); //$NON-NLS-1$ return; } else if ( !directoryFile.canWrite() ) { displayErrorMessage( Messages .getString( "ExportSchemasAsXmlWizardPage.ErrorSelectedDirectoryNotWritable" ) ); //$NON-NLS-1$ return; } } } else if ( exportSingleFileRadio.getSelection() ) { String exportFile = exportSingleFileText.getText(); if ( ( exportFile == null ) || ( exportFile.equals( "" ) ) ) //$NON-NLS-1$ { displayErrorMessage( Messages.getString( "ExportSchemasAsXmlWizardPage.ErrorNoFileSelected" ) ); //$NON-NLS-1$ return; } else { File file = new File( exportFile ); if ( !file.getParentFile().canWrite() ) { displayErrorMessage( Messages .getString( "ExportSchemasAsXmlWizardPage.ErrorSelectedFileNotWritable" ) ); //$NON-NLS-1$ return; } } } displayErrorMessage( null ); } /** * Gets the selected schemas. * * @return * the selected schemas */ public Schema[] getSelectedSchemas() { Object[] selectedSchemas = schemasTableViewer.getCheckedElements(); List<Schema> schemas = new ArrayList<Schema>(); for ( Object schema : selectedSchemas ) { schemas.add( ( Schema ) schema ); } return schemas.toArray( new Schema[0] ); } /** * Sets the selected projects. * * @param schemas * the schemas */ public void setSelectedSchemas( Schema[] schemas ) { selectedSchemas = schemas; } /** * Gets the type of export. * <p> * Values can either EXPORT_MULTIPLE_FILES or EXPORT_SINGLE_FILE. * * @return * the type of export */ public int getExportType() { if ( exportMultipleFilesRadio.getSelection() ) { return EXPORT_MULTIPLE_FILES; } else if ( exportSingleFileRadio.getSelection() ) { return EXPORT_SINGLE_FILE; } // Default return EXPORT_MULTIPLE_FILES; } /** * Gets the export directory. * * @return * the export directory */ public String getExportDirectory() { return exportMultipleFilesText.getText(); } /** * Gets the export file. * * @return * the export file */ public String getExportFile() { return exportSingleFileText.getText(); } /** * Saves the dialog settings. */ public void saveDialogSettings() { if ( exportMultipleFilesRadio.getSelection() ) { Activator.getDefault().getPreferenceStore().putValue( PluginConstants.FILE_DIALOG_EXPORT_SCHEMAS_XML, exportMultipleFilesText.getText() ); } else { Activator.getDefault().getPreferenceStore().putValue( PluginConstants.FILE_DIALOG_EXPORT_SCHEMAS_XML, new File( exportSingleFileText.getText() ).getParent() ); } } }
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/wizards/ExportSchemasAsOpenLdapWizardPage.java
plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/wizards/ExportSchemasAsOpenLdapWizardPage.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.wizards; import java.io.File; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.List; 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.eclipse.jface.viewers.ArrayContentProvider; import org.eclipse.jface.viewers.CheckStateChangedEvent; import org.eclipse.jface.viewers.CheckboxTableViewer; import org.eclipse.jface.viewers.ICheckStateListener; import org.eclipse.jface.viewers.LabelProvider; 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.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.DirectoryDialog; import org.eclipse.swt.widgets.Group; import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Table; import org.eclipse.swt.widgets.Text; import org.eclipse.ui.PlatformUI; /** * This class represents the WizardPage of the ExportSchemasAsOpenLdapWizard. * <p> * It is used to let the user enter the informations about the * schemas he wants to export and where to export. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class ExportSchemasAsOpenLdapWizardPage extends AbstractWizardPage { /** The selected schemas */ private Schema[] selectedSchemas = new Schema[0]; /** The SchemaHandler */ private SchemaHandler schemaHandler; // UI Fields private CheckboxTableViewer schemasTableViewer; private Button schemasTableSelectAllButton; private Button schemasTableDeselectAllButton; private Label exportDirectoryLabel; private Text exportDirectoryText; private Button exportDirectoryButton; /** * Creates a new instance of ExportSchemasAsXmlWizardPage. */ protected ExportSchemasAsOpenLdapWizardPage() { super( "ExportSchemasAsOpenLdapWizardPage" ); //$NON-NLS-1$ setTitle( Messages.getString( "ExportSchemasAsOpenLdapWizardPage.ExportSchemaAsOpenLDAP" ) ); //$NON-NLS-1$ setDescription( Messages.getString( "ExportSchemasAsOpenLdapWizardPage.PleaseSelectSchemaExportOpenLDAP" ) ); //$NON-NLS-1$ setImageDescriptor( Activator.getDefault().getImageDescriptor( PluginConstants.IMG_SCHEMAS_EXPORT_WIZARD ) ); schemaHandler = Activator.getDefault().getSchemaHandler(); } /** * {@inheritDoc} */ public void createControl( Composite parent ) { Composite composite = new Composite( parent, SWT.NULL ); GridLayout layout = new GridLayout(); composite.setLayout( layout ); // Schemas Group Group schemasGroup = new Group( composite, SWT.NONE ); schemasGroup.setText( Messages.getString( "ExportSchemasAsOpenLdapWizardPage.Schemas" ) ); //$NON-NLS-1$ schemasGroup.setLayout( new GridLayout( 2, false ) ); schemasGroup.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) ); // Schemas TableViewer Label schemasLabel = new Label( schemasGroup, SWT.NONE ); schemasLabel.setText( Messages.getString( "ExportSchemasAsOpenLdapWizardPage.SelectSchemasToExport" ) ); //$NON-NLS-1$ schemasLabel.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false, 2, 1 ) ); schemasTableViewer = new CheckboxTableViewer( new Table( schemasGroup, SWT.BORDER | SWT.CHECK | SWT.FULL_SELECTION ) ); GridData schemasTableViewerGridData = new GridData( SWT.FILL, SWT.NONE, true, false, 1, 2 ); schemasTableViewerGridData.heightHint = 125; schemasTableViewer.getTable().setLayoutData( schemasTableViewerGridData ); schemasTableViewer.setContentProvider( new ArrayContentProvider() ); schemasTableViewer.setLabelProvider( new LabelProvider() { public String getText( Object element ) { if ( element instanceof Schema ) { return ( ( Schema ) element ).getSchemaName(); } // Default return super.getText( element ); } public Image getImage( Object element ) { if ( element instanceof Schema ) { return Activator.getDefault().getImage( PluginConstants.IMG_SCHEMA ); } // Default return super.getImage( element ); } } ); schemasTableViewer.addCheckStateListener( new ICheckStateListener() { /** * Notifies of a change to the checked state of an element. * * @param event * event object describing the change */ public void checkStateChanged( CheckStateChangedEvent event ) { dialogChanged(); } } ); schemasTableSelectAllButton = new Button( schemasGroup, SWT.PUSH ); schemasTableSelectAllButton.setText( Messages.getString( "ExportSchemasAsOpenLdapWizardPage.SelectAll" ) ); //$NON-NLS-1$ schemasTableSelectAllButton.setLayoutData( new GridData( SWT.FILL, SWT.BEGINNING, false, false ) ); schemasTableSelectAllButton.addSelectionListener( new SelectionAdapter() { public void widgetSelected( SelectionEvent e ) { schemasTableViewer.setAllChecked( true ); dialogChanged(); } } ); schemasTableDeselectAllButton = new Button( schemasGroup, SWT.PUSH ); schemasTableDeselectAllButton.setText( Messages.getString( "ExportSchemasAsOpenLdapWizardPage.DeselectAll" ) ); //$NON-NLS-1$ schemasTableDeselectAllButton.setLayoutData( new GridData( SWT.FILL, SWT.BEGINNING, false, false ) ); schemasTableDeselectAllButton.addSelectionListener( new SelectionAdapter() { public void widgetSelected( SelectionEvent e ) { schemasTableViewer.setAllChecked( false ); dialogChanged(); } } ); // Export Destination Group Group exportDestinationGroup = new Group( composite, SWT.NULL ); exportDestinationGroup.setText( Messages.getString( "ExportSchemasAsOpenLdapWizardPage.ExportDestination" ) ); //$NON-NLS-1$ exportDestinationGroup.setLayout( new GridLayout( 3, false ) ); exportDestinationGroup.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) ); exportDirectoryLabel = new Label( exportDestinationGroup, SWT.NONE ); exportDirectoryLabel.setText( Messages.getString( "ExportSchemasAsOpenLdapWizardPage.Directory" ) ); //$NON-NLS-1$ exportDirectoryText = new Text( exportDestinationGroup, SWT.BORDER ); exportDirectoryText.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) ); exportDirectoryText.addModifyListener( new ModifyListener() { public void modifyText( ModifyEvent e ) { dialogChanged(); } } ); exportDirectoryButton = new Button( exportDestinationGroup, SWT.PUSH ); exportDirectoryButton.setText( Messages.getString( "ExportSchemasAsOpenLdapWizardPage.Browse" ) ); //$NON-NLS-1$ exportDirectoryButton.addSelectionListener( new SelectionAdapter() { public void widgetSelected( SelectionEvent e ) { chooseExportDirectory(); dialogChanged(); } } ); initFields(); dialogChanged(); setControl( composite ); } /** * Initializes the UI Fields. */ private void initFields() { // Filling the Schemas table if ( schemaHandler != null ) { List<Schema> schemas = new ArrayList<Schema>(); schemas.addAll( schemaHandler.getSchemas() ); Collections.sort( schemas, new Comparator<Schema>() { public int compare( Schema o1, Schema o2 ) { return o1.getSchemaName().compareToIgnoreCase( o2.getSchemaName() ); } } ); schemasTableViewer.setInput( schemas ); // Setting the selected schemas schemasTableViewer.setCheckedElements( selectedSchemas ); } displayErrorMessage( null ); setPageComplete( false ); } /** * This method is called when the exportMultipleFiles 'browse' button is selected. */ private void chooseExportDirectory() { DirectoryDialog dialog = new DirectoryDialog( PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell() ); dialog.setText( Messages.getString( "ExportSchemasAsOpenLdapWizardPage.ChooseFolder" ) ); //$NON-NLS-1$ dialog.setMessage( Messages.getString( "ExportSchemasAsOpenLdapWizardPage.SelectFolderToExport" ) ); //$NON-NLS-1$ if ( "".equals( exportDirectoryText.getText() ) ) //$NON-NLS-1$ { dialog.setFilterPath( Activator.getDefault().getPreferenceStore().getString( PluginConstants.FILE_DIALOG_EXPORT_SCHEMAS_OPENLDAP ) ); } else { dialog.setFilterPath( exportDirectoryText.getText() ); } String selectedDirectory = dialog.open(); if ( selectedDirectory != null ) { exportDirectoryText.setText( selectedDirectory ); } } /** * This method is called when the user modifies something in the UI. */ private void dialogChanged() { // Checking if a Schema Project is open if ( schemaHandler == null ) { displayErrorMessage( Messages.getString( "ExportSchemasAsOpenLdapWizardPage.ErrorNoOpenSchemaProject" ) ); //$NON-NLS-1$ return; } // Schemas table if ( schemasTableViewer.getCheckedElements().length == 0 ) { displayErrorMessage( Messages.getString( "ExportSchemasAsOpenLdapWizardPage.ErrorNoSchemaSelected" ) ); //$NON-NLS-1$ return; } // Export Directory String directory = exportDirectoryText.getText(); if ( ( directory == null ) || ( directory.equals( "" ) ) ) //$NON-NLS-1$ { displayErrorMessage( Messages.getString( "ExportSchemasAsOpenLdapWizardPage.ErrorNotDirectorySelected" ) ); //$NON-NLS-1$ return; } else { File directoryFile = new File( directory ); if ( !directoryFile.exists() ) { displayErrorMessage( Messages .getString( "ExportSchemasAsOpenLdapWizardPage.ErrorSelectedDirectoryNotExists" ) ); //$NON-NLS-1$ return; } else if ( !directoryFile.isDirectory() ) { displayErrorMessage( Messages .getString( "ExportSchemasAsOpenLdapWizardPage.ErrorSelectedDirectoryNotDirectory" ) ); //$NON-NLS-1$ return; } else if ( !directoryFile.canWrite() ) { displayErrorMessage( Messages .getString( "ExportSchemasAsOpenLdapWizardPage.ErrorSelectedDirectoryNotWritable" ) ); //$NON-NLS-1$ return; } } displayErrorMessage( null ); } /** * Gets the selected schemas. * * @return * the selected schemas */ public Schema[] getSelectedSchemas() { Object[] selectedSchemas = schemasTableViewer.getCheckedElements(); List<Schema> schemas = new ArrayList<Schema>(); for ( Object schema : selectedSchemas ) { schemas.add( ( Schema ) schema ); } return schemas.toArray( new Schema[0] ); } /** * Sets the selected projects. * * @param schemas * the schemas */ public void setSelectedSchemas( Schema[] schemas ) { selectedSchemas = schemas; } /** * Gets the export directory. * * @return * the export directory */ public String getExportDirectory() { return exportDirectoryText.getText(); } /** * Saves the dialog settings. */ public void saveDialogSettings() { Activator.getDefault().getPreferenceStore().putValue( PluginConstants.FILE_DIALOG_EXPORT_SCHEMAS_OPENLDAP, exportDirectoryText.getText() ); } }
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/wizards/ImportProjectsWizardPage.java
plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/wizards/ImportProjectsWizardPage.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.wizards; import java.io.File; import java.util.ArrayList; import java.util.List; import org.apache.directory.studio.schemaeditor.Activator; import org.apache.directory.studio.schemaeditor.PluginConstants; import org.eclipse.jface.viewers.ArrayContentProvider; import org.eclipse.jface.viewers.CheckStateChangedEvent; import org.eclipse.jface.viewers.CheckboxTableViewer; import org.eclipse.jface.viewers.ICheckStateListener; import org.eclipse.jface.viewers.LabelProvider; 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.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.DirectoryDialog; import org.eclipse.swt.widgets.Group; import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Table; import org.eclipse.swt.widgets.Text; import org.eclipse.ui.PlatformUI; /** * This class represents the WizardPage of the ImportProjectsWizard. * <p> * It is used to let the user enter the informations about the * schemas he wants to import. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class ImportProjectsWizardPage extends AbstractWizardPage { // UI Fields private Text fromDirectoryText; private Button fromDirectoryButton; private CheckboxTableViewer projectFilesTableViewer; private Button projectFilesTableSelectAllButton; private Button projectFilesTableDeselectAllButton; /** * Creates a new instance of ImportSchemasFromOpenLdapWizardPage. */ protected ImportProjectsWizardPage() { super( "ImportProjectsWizardPage" ); //$NON-NLS-1$ setTitle( Messages.getString( "ImportProjectsWizardPage.ImportSchemaProjects" ) ); //$NON-NLS-1$ setDescription( Messages.getString( "ImportProjectsWizardPage.SelechtSchemaProject" ) ); //$NON-NLS-1$ setImageDescriptor( Activator.getDefault().getImageDescriptor( PluginConstants.IMG_PROJECT_IMPORT_WIZARD ) ); } /** * {@inheritDoc} */ public void createControl( Composite parent ) { Composite composite = new Composite( parent, SWT.NULL ); GridLayout layout = new GridLayout(); composite.setLayout( layout ); // From Directory Group Group fromDirectoryGroup = new Group( composite, SWT.NONE ); fromDirectoryGroup.setText( Messages.getString( "ImportProjectsWizardPage.FromDirectory" ) ); //$NON-NLS-1$ fromDirectoryGroup.setLayout( new GridLayout( 3, false ) ); fromDirectoryGroup.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) ); // From Directory Label fromDirectoryLabel = new Label( fromDirectoryGroup, SWT.NONE ); fromDirectoryLabel.setText( Messages.getString( "ImportProjectsWizardPage.FromDirectoryColon" ) ); //$NON-NLS-1$ fromDirectoryText = new Text( fromDirectoryGroup, SWT.BORDER ); fromDirectoryText.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) ); fromDirectoryText.addModifyListener( new ModifyListener() { public void modifyText( ModifyEvent e ) { dialogChanged(); } } ); fromDirectoryButton = new Button( fromDirectoryGroup, SWT.PUSH ); fromDirectoryButton.setText( Messages.getString( "ImportProjectsWizardPage.Browse" ) ); //$NON-NLS-1$ fromDirectoryButton.addSelectionListener( new SelectionAdapter() { public void widgetSelected( SelectionEvent e ) { chooseFromDirectory(); } } ); // Schema Files Group Group schemaFilesGroup = new Group( composite, SWT.NONE ); schemaFilesGroup.setText( Messages.getString( "ImportProjectsWizardPage.SchemaProjectFiles" ) ); //$NON-NLS-1$ schemaFilesGroup.setLayout( new GridLayout( 2, false ) ); schemaFilesGroup.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) ); // Schema Files projectFilesTableViewer = new CheckboxTableViewer( new Table( schemaFilesGroup, SWT.BORDER | SWT.CHECK | SWT.FULL_SELECTION ) ); GridData schemasTableViewerGridData = new GridData( SWT.FILL, SWT.NONE, true, false, 1, 2 ); schemasTableViewerGridData.heightHint = 125; projectFilesTableViewer.getTable().setLayoutData( schemasTableViewerGridData ); projectFilesTableViewer.setContentProvider( new ArrayContentProvider() ); projectFilesTableViewer.setLabelProvider( new LabelProvider() { public String getText( Object element ) { if ( element instanceof File ) { return ( ( File ) element ).getName(); } // Default return super.getText( element ); } public Image getImage( Object element ) { if ( element instanceof File ) { return Activator.getDefault().getImage( PluginConstants.IMG_PROJECT_FILE ); } // Default return super.getImage( element ); } } ); projectFilesTableViewer.addCheckStateListener( new ICheckStateListener() { /** * Notifies of a change to the checked state of an element. * * @param event * event object describing the change */ public void checkStateChanged( CheckStateChangedEvent event ) { dialogChanged(); } } ); projectFilesTableSelectAllButton = new Button( schemaFilesGroup, SWT.PUSH ); projectFilesTableSelectAllButton.setText( Messages.getString( "ImportProjectsWizardPage.SelectAll" ) ); //$NON-NLS-1$ projectFilesTableSelectAllButton.setLayoutData( new GridData( SWT.FILL, SWT.BEGINNING, false, false ) ); projectFilesTableSelectAllButton.addSelectionListener( new SelectionAdapter() { public void widgetSelected( SelectionEvent e ) { projectFilesTableViewer.setAllChecked( true ); dialogChanged(); } } ); projectFilesTableDeselectAllButton = new Button( schemaFilesGroup, SWT.PUSH ); projectFilesTableDeselectAllButton.setText( Messages.getString( "ImportProjectsWizardPage.DeselectAll" ) ); //$NON-NLS-1$ projectFilesTableDeselectAllButton.setLayoutData( new GridData( SWT.FILL, SWT.BEGINNING, false, false ) ); projectFilesTableDeselectAllButton.addSelectionListener( new SelectionAdapter() { public void widgetSelected( SelectionEvent e ) { projectFilesTableViewer.setAllChecked( false ); dialogChanged(); } } ); initFields(); setControl( composite ); } /** * Initializes the UI Fields. */ private void initFields() { displayErrorMessage( null ); setPageComplete( false ); } /** * This method is called when the exportMultipleFiles 'browse' button is selected. */ private void chooseFromDirectory() { DirectoryDialog dialog = new DirectoryDialog( PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell() ); dialog.setText( Messages.getString( "ImportProjectsWizardPage.ChooseFolder" ) ); //$NON-NLS-1$ dialog.setMessage( Messages.getString( "ImportProjectsWizardPage.SelectFoldertoImportFrom" ) ); //$NON-NLS-1$ if ( "".equals( fromDirectoryText.getText() ) ) //$NON-NLS-1$ { dialog.setFilterPath( Activator.getDefault().getPreferenceStore().getString( PluginConstants.FILE_DIALOG_IMPORT_PROJECTS ) ); } else { dialog.setFilterPath( fromDirectoryText.getText() ); } String selectedDirectory = dialog.open(); if ( selectedDirectory != null ) { fromDirectoryText.setText( selectedDirectory ); fillInSchemaFilesTable( selectedDirectory ); } } /** * Fills in the SchemaFilesTable with the schema files found in the given path. * * @param path * the path to search schema files in */ private void fillInSchemaFilesTable( String path ) { List<File> schemaFiles = new ArrayList<File>(); File selectedDirectory = new File( path ); if ( selectedDirectory.exists() ) { for ( File file : selectedDirectory.listFiles() ) { String fileName = file.getName(); if ( fileName.endsWith( ".schemaproject" ) ) //$NON-NLS-1$ { schemaFiles.add( file ); } } } projectFilesTableViewer.setInput( schemaFiles ); } /** * This method is called when the user modifies something in the UI. */ private void dialogChanged() { // Export Directory String directory = fromDirectoryText.getText(); if ( ( directory == null ) || ( directory.equals( "" ) ) ) //$NON-NLS-1$ { displayErrorMessage( Messages.getString( "ImportProjectsWizardPage.ErrorNoDirectorySelected" ) ); //$NON-NLS-1$ return; } else { File directoryFile = new File( directory ); if ( !directoryFile.exists() ) { displayErrorMessage( Messages.getString( "ImportProjectsWizardPage.ErrorSelectedDirectoryNotExists" ) ); //$NON-NLS-1$ return; } else if ( !directoryFile.isDirectory() ) { displayErrorMessage( Messages.getString( "ImportProjectsWizardPage.ErrorSelectedDirectoryNotDirectory" ) ); //$NON-NLS-1$ return; } else if ( !directoryFile.canRead() ) { displayErrorMessage( Messages.getString( "ImportProjectsWizardPage.ErrorSelectedDirectoryNotReadable" ) ); //$NON-NLS-1$ return; } } // Schemas table if ( projectFilesTableViewer.getCheckedElements().length == 0 ) { displayErrorMessage( Messages.getString( "ImportProjectsWizardPage.ErrorNoSchemaProjectSelected" ) ); //$NON-NLS-1$ return; } displayErrorMessage( null ); } /** * Gets the selected project files. * * @return * the selected project files */ public File[] getSelectedProjectFiles() { Object[] selectedProjectFile = projectFilesTableViewer.getCheckedElements(); List<File> schemaFiles = new ArrayList<File>(); for ( Object projectFile : selectedProjectFile ) { schemaFiles.add( ( File ) projectFile ); } return schemaFiles.toArray( new File[0] ); } /** * Saves the dialog settings. */ public void saveDialogSettings() { Activator.getDefault().getPreferenceStore().putValue( PluginConstants.FILE_DIALOG_IMPORT_PROJECTS, fromDirectoryText.getText() ); } }
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/wizards/ImportProjectsWizard.java
plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/wizards/ImportProjectsWizard.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.wizards; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.lang.reflect.InvocationTargetException; import org.apache.directory.studio.schemaeditor.Activator; import org.apache.directory.studio.schemaeditor.PluginUtils; import org.apache.directory.studio.schemaeditor.controller.ProjectsHandler; import org.apache.directory.studio.schemaeditor.model.Project; import org.apache.directory.studio.schemaeditor.model.io.ProjectsImportException; import org.apache.directory.studio.schemaeditor.model.io.ProjectsImporter; import org.apache.directory.studio.schemaeditor.view.ViewUtils; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.jface.operation.IRunnableWithProgress; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jface.wizard.Wizard; import org.eclipse.osgi.util.NLS; import org.eclipse.ui.IImportWizard; import org.eclipse.ui.IWorkbench; /** * This class represents the wizard to import schema projects. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class ImportProjectsWizard extends Wizard implements IImportWizard { // The pages of the wizard private ImportProjectsWizardPage page; /** The ProjectsHandler */ private ProjectsHandler projectsHandler; /** * {@inheritDoc} */ public void addPages() { // Creating pages page = new ImportProjectsWizardPage(); // Adding pages addPage( page ); } /** * {@inheritDoc} */ public boolean performFinish() { // Saving the dialog settings page.saveDialogSettings(); // Getting the projects to be imported final File[] selectedProjectFiles = page.getSelectedProjectFiles(); try { getContainer().run( false, false, new IRunnableWithProgress() { public void run( IProgressMonitor monitor ) { monitor.beginTask( Messages.getString( "ImportProjectsWizard.ImportingProjects" ), selectedProjectFiles.length ); //$NON-NLS-1$ for ( File projectFile : selectedProjectFiles ) { monitor.subTask( projectFile.getName() ); try { Project project = ProjectsImporter.getProject( new FileInputStream( projectFile ), projectFile.getAbsolutePath() ); if ( projectsHandler.isProjectNameAlreadyTaken( project.getName() ) ) { PluginUtils .logError( NLS .bind( Messages.getString( "ImportProjectsWizard.ErrorImportingProject" ), //$NON-NLS-1$ new String[] { project.getName() } ), null ); ViewUtils .displayErrorMessageDialog( Messages.getString( "ImportProjectsWizard.ImportError" ), //$NON-NLS-1$ NLS .bind( Messages.getString( "ImportProjectsWizard.ErrorImportingProject" ) //$NON-NLS-1$ + "\n" //$NON-NLS-1$ + Messages .getString( "ImportProjectsWizard.ErrorProjectNameExists" ), //$NON-NLS-1$ new String[] { project.getName() } ) ); } else { projectsHandler.addProject( project ); } } catch ( ProjectsImportException e ) { PluginUtils .logError( NLS .bind( Messages.getString( "ImportProjectsWizard.ErrorImportingProject" ), new String[] { projectFile.getName() } ), e ); //$NON-NLS-1$ ViewUtils .displayErrorMessageDialog( Messages.getString( "ImportProjectsWizard.ImportError" ), //$NON-NLS-1$ NLS .bind( Messages.getString( "ImportProjectsWizard.ErrorImportingProject" ), new String[] { projectFile.getName() } ) ); //$NON-NLS-1$ } catch ( FileNotFoundException e ) { PluginUtils .logError( NLS .bind( Messages.getString( "ImportProjectsWizard.ErrorImportingProject" ), new String[] { projectFile.getName() } ), e ); //$NON-NLS-1$ ViewUtils .displayErrorMessageDialog( Messages.getString( "ImportProjectsWizard.ImportError" ), //$NON-NLS-1$ NLS .bind( Messages.getString( "ImportProjectsWizard.ErrorImportingProject" ), new String[] { projectFile.getName() } ) ); //$NON-NLS-1$ } monitor.worked( 1 ); } monitor.done(); } } ); } catch ( InvocationTargetException e ) { // Nothing to do (it will never occur) } catch ( InterruptedException e ) { // Nothing to do. } return true; } /** * {@inheritDoc} */ public void init( IWorkbench workbench, IStructuredSelection selection ) { setNeedsProgressMonitor( true ); projectsHandler = Activator.getDefault().getProjectsHandler(); } }
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/wizards/MergeSchemasOptionsWizardPage.java
plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/wizards/MergeSchemasOptionsWizardPage.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.wizards; import org.apache.directory.studio.common.ui.widgets.BaseWidgetUtils; import org.apache.directory.studio.schemaeditor.Activator; import org.apache.directory.studio.schemaeditor.PluginConstants; import org.eclipse.jface.wizard.WizardPage; 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.Composite; /** * This class represents the page to select options of the MergeSchemasWizard. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class MergeSchemasOptionsWizardPage extends WizardPage { // UI Fields private Button replaceUnknowNSyntaxButton; private Button mergeDependenciesButton; private Button pullUpAttributesButton; /** * Creates a new instance of MergeSchemasOptionsWizardPage. */ protected MergeSchemasOptionsWizardPage() { super( "MergeSchemasOptionsWizardPage" ); //$NON-NLS-1$ setTitle( Messages.getString( "MergeSchemasSelectionWizardPage.ImportSchemasFromProjects" ) ); //$NON-NLS-1$ setDescription( Messages.getString( "MergeSchemasSelectionWizardPage.SelectOptions" ) ); //$NON-NLS-1$ setImageDescriptor( Activator.getDefault().getImageDescriptor( PluginConstants.IMG_SCHEMAS_IMPORT_WIZARD ) ); } /** * {@inheritDoc} */ public void createControl( Composite parent ) { Composite composite = new Composite( parent, SWT.NULL ); GridLayout layout = new GridLayout(); composite.setLayout( layout ); composite.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) ); replaceUnknowNSyntaxButton = BaseWidgetUtils.createCheckbox( composite, Messages .getString( "MergeSchemasOptionsWizardPage.ReplaceUnknownSyntax" ), 1 ); //$NON-NLS-1$ replaceUnknowNSyntaxButton.setToolTipText( Messages .getString( "MergeSchemasOptionsWizardPage.ReplaceUnknownSyntaxTooltip" ) ); //$NON-NLS-1$ replaceUnknowNSyntaxButton.setSelection( true ); mergeDependenciesButton = BaseWidgetUtils.createCheckbox( composite, Messages .getString( "MergeSchemasOptionsWizardPage.MergeDependencies" ), 1 ); //$NON-NLS-1$ mergeDependenciesButton.setToolTipText( Messages .getString( "MergeSchemasOptionsWizardPage.MergeDependenciesTooltip" ) ); //$NON-NLS-1$ mergeDependenciesButton.setSelection( true ); pullUpAttributesButton = BaseWidgetUtils.createCheckbox( composite, Messages .getString( "MergeSchemasOptionsWizardPage.PullUpAttributes" ), 1 ); //$NON-NLS-1$ pullUpAttributesButton.setToolTipText( Messages .getString( "MergeSchemasOptionsWizardPage.PullUpAttributesTooltip" ) ); //$NON-NLS-1$ pullUpAttributesButton.setSelection( true ); setControl( composite ); } public boolean isReplaceUnknownSyntax() { return replaceUnknowNSyntaxButton.getSelection(); } public boolean isMergeDependencies() { return mergeDependenciesButton.getSelection(); } public boolean isPullUpAttributes() { return pullUpAttributesButton.getSelection(); } }
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/wizards/NewObjectClassOptionalAttributesPage.java
plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/wizards/NewObjectClassOptionalAttributesPage.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.wizards; 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.PluginConstants; import org.apache.directory.studio.schemaeditor.view.ViewUtils; import org.apache.directory.studio.schemaeditor.view.dialogs.AttributeTypeSelectionDialog; import org.eclipse.jface.dialogs.Dialog; import org.eclipse.jface.viewers.ArrayContentProvider; import org.eclipse.jface.viewers.ISelectionChangedListener; import org.eclipse.jface.viewers.LabelProvider; import org.eclipse.jface.viewers.SelectionChangedEvent; import org.eclipse.jface.viewers.StructuredSelection; import org.eclipse.jface.viewers.TableViewer; import org.eclipse.jface.wizard.WizardPage; import org.eclipse.osgi.util.NLS; import org.eclipse.swt.SWT; 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.Group; import org.eclipse.swt.widgets.Table; /** * This class represents the Optional Attribute Types WizardPage of the NewObjectClassWizard. * <p> * It is used to let the user specify the optional attribute types for the object class. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class NewObjectClassOptionalAttributesPage extends WizardPage { /** The optional attribute types list */ private List<AttributeType> optionalAttributeTypesList; // UI Fields private TableViewer optionalAttributeTypesTableViewer; private Button optionalAttributeTypesAddButton; private Button optionalAttributeTypesRemoveButton; /** * Creates a new instance of NewObjectClassOptionalAttributesPage. */ protected NewObjectClassOptionalAttributesPage() { super( "NewObjectClassOptionalAttributesPage" ); //$NON-NLS-1$ setTitle( Messages.getString( "NewObjectClassOptionalAttributesPage.OptionalAttributeTypes" ) ); //$NON-NLS-1$ setDescription( Messages .getString( "NewObjectClassOptionalAttributesPage.SpecifiyOptionalAttributeTypesForObjectClass" ) ); //$NON-NLS-1$ setImageDescriptor( Activator.getDefault().getImageDescriptor( PluginConstants.IMG_OBJECT_CLASS_NEW_WIZARD ) ); optionalAttributeTypesList = new ArrayList<AttributeType>(); } /** * {@inheritDoc} */ public void createControl( Composite parent ) { Composite composite = new Composite( parent, SWT.NULL ); GridLayout layout = new GridLayout(); composite.setLayout( layout ); // Optional Attribute Types Group Group optionalAttributeTypesGroup = new Group( composite, SWT.NONE ); optionalAttributeTypesGroup.setText( Messages .getString( "NewObjectClassOptionalAttributesPage.OptionalAttributeTypes" ) ); //$NON-NLS-1$ optionalAttributeTypesGroup.setLayout( new GridLayout( 2, false ) ); optionalAttributeTypesGroup.setLayoutData( new GridData( SWT.FILL, SWT.FILL, true, true ) ); // Optional Attribute Types Table optionalAttributeTypesTable = new Table( optionalAttributeTypesGroup, SWT.BORDER ); GridData optionalAttributeTypesTableGridData = new GridData( SWT.FILL, SWT.FILL, true, true, 1, 2 ); optionalAttributeTypesTableGridData.heightHint = 100; optionalAttributeTypesTable.setLayoutData( optionalAttributeTypesTableGridData ); optionalAttributeTypesTableViewer = new TableViewer( optionalAttributeTypesTable ); optionalAttributeTypesTableViewer.setContentProvider( new ArrayContentProvider() ); optionalAttributeTypesTableViewer.setLabelProvider( new LabelProvider() { public Image getImage( Object element ) { if ( element instanceof AttributeType ) { return Activator.getDefault().getImage( PluginConstants.IMG_ATTRIBUTE_TYPE ); } // Default return super.getImage( element ); } public String getText( Object element ) { if ( element instanceof AttributeType ) { AttributeType at = ( AttributeType ) element; List<String> names = at.getNames(); if ( ( names != null ) && ( names.size() > 0 ) ) { return NLS .bind( Messages.getString( "NewObjectClassOptionalAttributesPage.AliasOID" ), new String[] { ViewUtils.concateAliases( names ), at.getOid() } ); //$NON-NLS-1$ } else { return NLS .bind( Messages.getString( "NewObjectClassOptionalAttributesPage.NoneOID" ), new String[] { at.getOid() } ); //$NON-NLS-1$ } } // Default return super.getText( element ); } } ); optionalAttributeTypesTableViewer.setInput( optionalAttributeTypesList ); optionalAttributeTypesTableViewer.addSelectionChangedListener( new ISelectionChangedListener() { public void selectionChanged( SelectionChangedEvent event ) { optionalAttributeTypesRemoveButton.setEnabled( !event.getSelection().isEmpty() ); } } ); optionalAttributeTypesAddButton = new Button( optionalAttributeTypesGroup, SWT.PUSH ); optionalAttributeTypesAddButton.setText( Messages.getString( "NewObjectClassOptionalAttributesPage.Add" ) ); //$NON-NLS-1$ optionalAttributeTypesAddButton.setLayoutData( new GridData( SWT.FILL, SWT.NONE, false, false ) ); optionalAttributeTypesAddButton.addSelectionListener( new SelectionAdapter() { public void widgetSelected( SelectionEvent arg0 ) { addOptionalAttributeType(); } } ); optionalAttributeTypesRemoveButton = new Button( optionalAttributeTypesGroup, SWT.PUSH ); optionalAttributeTypesRemoveButton .setText( Messages.getString( "NewObjectClassOptionalAttributesPage.Remove" ) ); //$NON-NLS-1$ optionalAttributeTypesRemoveButton.setLayoutData( new GridData( SWT.FILL, SWT.NONE, false, false ) ); optionalAttributeTypesRemoveButton.addSelectionListener( new SelectionAdapter() { public void widgetSelected( SelectionEvent arg0 ) { removeOptionalAttributeType(); } } ); optionalAttributeTypesRemoveButton.setEnabled( false ); setControl( composite ); } /** * This method is called when the "Add" button of the optional * attribute types table is selected. */ private void addOptionalAttributeType() { AttributeTypeSelectionDialog dialog = new AttributeTypeSelectionDialog(); List<AttributeType> hiddenAttributes = new ArrayList<AttributeType>(); hiddenAttributes.addAll( optionalAttributeTypesList ); dialog.setHiddenAttributeTypes( hiddenAttributes ); if ( dialog.open() == Dialog.OK ) { optionalAttributeTypesList.add( dialog.getSelectedAttributeType() ); updateOptionalAttributeTypesTableTable(); } } /** * This method is called when the "Remove" button of the optional * attribute types table is selected. */ private void removeOptionalAttributeType() { StructuredSelection selection = ( StructuredSelection ) optionalAttributeTypesTableViewer.getSelection(); if ( !selection.isEmpty() ) { optionalAttributeTypesList.remove( selection.getFirstElement() ); updateOptionalAttributeTypesTableTable(); } } /** * Updates the optional attribute types table. */ private void updateOptionalAttributeTypesTableTable() { Collections.sort( optionalAttributeTypesList, new Comparator<AttributeType>() { public int compare( AttributeType o1, AttributeType o2 ) { List<String> at1Names = o1.getNames(); List<String> at2Names = o2.getNames(); if ( ( at1Names != null ) && ( at2Names != null ) && ( at1Names.size() > 0 ) && ( at2Names.size() > 0 ) ) { return at1Names.get( 0 ).compareToIgnoreCase( at2Names.get( 0 ) ); } // Default return 0; } } ); optionalAttributeTypesTableViewer.refresh(); } /** * Gets the optional attribute types. * * @return * the optional attributes types */ public List<AttributeType> getOptionalAttributeTypes() { return optionalAttributeTypesList; } /** * Gets the names of the optional attribute types. * * @return * the names of the optional attributes types */ public List<String> getOptionalAttributeTypesNames() { List<String> names = new ArrayList<String>(); for ( AttributeType at : optionalAttributeTypesList ) { names.add( at.getName() ); } return names; } }
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/wizards/ImportSchemasFromOpenLdapWizard.java
plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/wizards/ImportSchemasFromOpenLdapWizard.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.wizards; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import org.apache.directory.studio.common.core.jobs.StudioProgressMonitor; import org.apache.directory.studio.connection.core.jobs.StudioConnectionRunnableWithProgress; import org.apache.directory.studio.connection.core.jobs.StudioConnectionRunnableWithProgressAdapter; import org.apache.directory.studio.connection.ui.RunnableContextRunner; import org.apache.directory.studio.schemaeditor.Activator; import org.apache.directory.studio.schemaeditor.controller.SchemaHandler; import org.apache.directory.studio.schemaeditor.model.Schema; import org.apache.directory.studio.schemaeditor.model.io.OpenLdapSchemaFileImportException; import org.apache.directory.studio.schemaeditor.model.io.OpenLdapSchemaFileImporter; import org.apache.directory.studio.schemaeditor.model.schemachecker.SchemaChecker; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jface.wizard.Wizard; import org.eclipse.osgi.util.NLS; import org.eclipse.ui.IImportWizard; import org.eclipse.ui.IWorkbench; /** * This class represents the wizard to import schemas from OpenLdap format. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class ImportSchemasFromOpenLdapWizard extends Wizard implements IImportWizard { /** The SchemaHandler */ private SchemaHandler schemaHandler; /** The SchemaChecker */ private SchemaChecker schemaChecker; // The pages of the wizard private ImportSchemasFromOpenLdapWizardPage page; /** * {@inheritDoc} */ public void addPages() { // Creating pages page = new ImportSchemasFromOpenLdapWizardPage(); // Adding pages addPage( page ); } /** * {@inheritDoc} */ public boolean performFinish() { // Saving the dialog settings page.saveDialogSettings(); // Getting the schemas to be imported final File[] selectedSchemasFiles = page.getSelectedSchemaFiles(); schemaChecker.disableModificationsListening(); StudioConnectionRunnableWithProgress runnable = new StudioConnectionRunnableWithProgressAdapter() { public void run( StudioProgressMonitor monitor ) { monitor .beginTask( Messages.getString( "ImportSchemasFromOpenLdapWizard.ImportingSchemas" ), selectedSchemasFiles.length ); //$NON-NLS-1$ for ( File schemaFile : selectedSchemasFiles ) { monitor.subTask( schemaFile.getName() ); try { Schema schema = OpenLdapSchemaFileImporter.getSchema( new FileInputStream( schemaFile ), schemaFile.getAbsolutePath() ); schema.setProject( Activator.getDefault().getProjectsHandler().getOpenProject() ); schemaHandler.addSchema( schema ); } catch ( OpenLdapSchemaFileImportException e ) { reportError( e, schemaFile, monitor ); } catch ( FileNotFoundException e ) { reportError( e, schemaFile, monitor ); } monitor.worked( 1 ); } } /** * Reports the error raised. * * @param e * the exception * @param schemaFile * the schema file * @param monitor * the monitor the error is reported to * */ private void reportError( Exception e, File schemaFile, StudioProgressMonitor monitor ) { String message = NLS.bind( Messages.getString( "ImportSchemasFromOpenLdapWizard.ErrorImportingSchema" ), schemaFile.getName() ); //$NON-NLS-1$ monitor.reportError( message, e ); } public String getName() { return Messages.getString( "ImportSchemasFromOpenLdapWizard.ImportingSchemas" ); //$NON-NLS-1$ } }; RunnableContextRunner.execute( runnable, getContainer(), true ); schemaChecker.enableModificationsListening(); return true; } /** * {@inheritDoc} */ public void init( IWorkbench workbench, IStructuredSelection selection ) { setNeedsProgressMonitor( true ); schemaHandler = Activator.getDefault().getSchemaHandler(); schemaChecker = Activator.getDefault().getSchemaChecker(); } }
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/wizards/MergeSchemasSelectionWizardPage.java
plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/wizards/MergeSchemasSelectionWizardPage.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.wizards; 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.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.ProjectType; import org.apache.directory.studio.schemaeditor.model.Schema; import org.eclipse.jface.viewers.CheckStateChangedEvent; import org.eclipse.jface.viewers.CheckboxTreeViewer; import org.eclipse.jface.viewers.ICheckStateListener; import org.eclipse.jface.viewers.ITreeContentProvider; import org.eclipse.jface.viewers.LabelProvider; import org.eclipse.jface.viewers.Viewer; import org.eclipse.jface.viewers.ViewerSorter; import org.eclipse.swt.SWT; import org.eclipse.swt.graphics.Image; 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; /** * This class represents the page to select merged elements of the MergeSchemasWizard. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class MergeSchemasSelectionWizardPage extends AbstractWizardPage { /** The selected projects */ private Project[] selectedProjects = new Project[0]; // UI Fields private CheckboxTreeViewer projectsTreeViewer; /** * Creates a new instance of MergeSchemasSelectionWizardPage. */ protected MergeSchemasSelectionWizardPage() { super( "MergeSchemasSelectionWizardPage" ); //$NON-NLS-1$ setTitle( Messages.getString( "MergeSchemasSelectionWizardPage.ImportSchemasFromProjects" ) ); //$NON-NLS-1$ setDescription( Messages.getString( "MergeSchemasSelectionWizardPage.PleaseSelectElements" ) ); //$NON-NLS-1$ setImageDescriptor( Activator.getDefault().getImageDescriptor( PluginConstants.IMG_SCHEMAS_IMPORT_WIZARD ) ); } /** * {@inheritDoc} */ public void createControl( Composite parent ) { Composite composite = new Composite( parent, SWT.NULL ); GridLayout layout = new GridLayout(); composite.setLayout( layout ); // Projects TreeViewer Label projectsLabel = new Label( composite, SWT.NONE ); projectsLabel.setText( Messages.getString( "MergeSchemasSelectionWizardPage.SelectElements" ) ); //$NON-NLS-1$ projectsLabel.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false, 1, 1 ) ); projectsTreeViewer = new CheckboxTreeViewer( new Tree( composite, SWT.BORDER | SWT.CHECK | SWT.FULL_SELECTION ) ); GridData projectsTableViewerGridData = new GridData( SWT.FILL, SWT.FILL, true, true, 1, 1 ); projectsTableViewerGridData.widthHint = 450; projectsTableViewerGridData.heightHint = 250; projectsTreeViewer.getTree().setLayoutData( projectsTableViewerGridData ); projectsTreeViewer.setContentProvider( new ITreeContentProvider() { public void inputChanged( Viewer viewer, Object oldInput, Object newInput ) { } public void dispose() { } public Object[] getElements( Object inputElement ) { return getChildren( inputElement ); } public boolean hasChildren( Object element ) { return getChildren( element ).length > 0; } public Object getParent( Object element ) { return null; } public Object[] getChildren( Object parentElement ) { if ( parentElement instanceof List<?> ) { return ( ( List<?> ) parentElement ).toArray(); } if ( parentElement instanceof Project ) { Project project = ( Project ) parentElement; List<Schema> schemas = project.getSchemaHandler().getSchemas(); return schemas.toArray(); } if ( parentElement instanceof Schema ) { Schema schema = ( Schema ) parentElement; Object[] children = new Object[] { new AttributeTypeFolder( schema ), new ObjectClassFolder( schema ) }; return children; } if ( parentElement instanceof AttributeTypeFolder ) { AttributeTypeFolder folder = ( AttributeTypeFolder ) parentElement; List<AttributeTypeWrapper> attributeTypeWrappers = new ArrayList<AttributeTypeWrapper>(); for ( AttributeType attributeType : folder.schema.getAttributeTypes() ) { attributeTypeWrappers.add( new AttributeTypeWrapper( attributeType, folder ) ); } return attributeTypeWrappers.toArray(); } if ( parentElement instanceof ObjectClassFolder ) { ObjectClassFolder folder = ( ObjectClassFolder ) parentElement; List<ObjectClassWrapper> objectClassWrappers = new ArrayList<ObjectClassWrapper>(); for ( ObjectClass objectClass : folder.schema.getObjectClasses() ) { objectClassWrappers.add( new ObjectClassWrapper( objectClass, folder ) ); } return objectClassWrappers.toArray(); } return new Object[0]; } } ); projectsTreeViewer.setLabelProvider( new LabelProvider() { public String getText( Object element ) { if ( element instanceof Project ) { return ( ( Project ) element ).getName(); } else if ( element instanceof Schema ) { return ( ( Schema ) element ).getSchemaName(); } else if ( element instanceof ObjectClassFolder ) { return Messages.getString( "MergeSchemasSelectionWizardPage.ObjectClasses" ); //$NON-NLS-1$ } else if ( element instanceof AttributeTypeFolder ) { return Messages.getString( "MergeSchemasSelectionWizardPage.AttributeTypes" ); //$NON-NLS-1$ } else if ( element instanceof AttributeTypeWrapper ) { AttributeType at = ( ( AttributeTypeWrapper ) element ).attributeType; List<String> names = at.getNames(); if ( ( names != null ) && ( names.size() > 0 ) ) { return names.get( 0 ); } else { return at.getOid(); } } else if ( element instanceof ObjectClassWrapper ) { ObjectClass oc = ( ( ObjectClassWrapper ) element ).objectClass; List<String> names = oc.getNames(); if ( ( names != null ) && ( names.size() > 0 ) ) { return names.get( 0 ); } else { return oc.getOid(); } } // Default return super.getText( element ); } public Image getImage( Object element ) { if ( element instanceof Project ) { ProjectType type = ( ( Project ) element ).getType(); switch ( type ) { case OFFLINE: return Activator.getDefault().getImage( PluginConstants.IMG_PROJECT_OFFLINE_CLOSED ); case ONLINE: return Activator.getDefault().getImage( PluginConstants.IMG_PROJECT_ONLINE_CLOSED ); } } else if ( element instanceof Schema ) { return Activator.getDefault().getImage( PluginConstants.IMG_SCHEMA ); } else if ( element instanceof ObjectClassFolder ) { return Activator.getDefault().getImage( PluginConstants.IMG_FOLDER_OC ); } else if ( element instanceof AttributeTypeFolder ) { return Activator.getDefault().getImage( PluginConstants.IMG_FOLDER_AT ); } 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 ); } // Default return super.getImage( element ); } } ); projectsTreeViewer.setSorter( new ViewerSorter() ); projectsTreeViewer.addCheckStateListener( new ICheckStateListener() { /** * Notifies of a change to the checked state of an element. * * @param event * event object describing the change */ public void checkStateChanged( CheckStateChangedEvent event ) { dialogChanged(); } } ); initFields(); setControl( composite ); } /** * Initializes the UI Fields. */ private void initFields() { // Filling the Schemas table List<Project> projects = new ArrayList<Project>(); projects.addAll( Activator.getDefault().getProjectsHandler().getProjects() ); Collections.sort( projects, new Comparator<Project>() { public int compare( Project o1, Project o2 ) { return o1.getName().compareToIgnoreCase( o2.getName() ); } } ); projectsTreeViewer.setInput( projects ); // Setting the selected projects projectsTreeViewer.setCheckedElements( selectedProjects ); displayErrorMessage( null ); setPageComplete( false ); } /** * This method is called when the user modifies something in the UI. */ private void dialogChanged() { // Schemas table if ( projectsTreeViewer.getCheckedElements().length == 0 ) { displayErrorMessage( Messages.getString( "MergeSchemasSelectionWizardPage.ErrorNoElementsSelected" ) ); //$NON-NLS-1$ return; } displayErrorMessage( null ); } /** * Gets the selected objects. * * @return * the selected objects */ public Object[] getSelectedObjects() { Object[] selectedObjects = projectsTreeViewer.getCheckedElements(); return selectedObjects; } /** * Sets the selected projects. * * @param projects * the projects */ public void setSelectedProjects( Project[] projects ) { selectedProjects = projects; } class ObjectClassFolder { Schema schema; public ObjectClassFolder( Schema schema ) { this.schema = schema; } } class AttributeTypeFolder { Schema schema; public AttributeTypeFolder( Schema schema ) { this.schema = schema; } } class ObjectClassWrapper { ObjectClass objectClass; ObjectClassFolder folder; public ObjectClassWrapper( ObjectClass objectClass, ObjectClassFolder folder ) { this.objectClass = objectClass; this.folder = folder; } } class AttributeTypeWrapper { AttributeType attributeType; AttributeTypeFolder folder; public AttributeTypeWrapper( AttributeType attributeType, AttributeTypeFolder folder ) { this.attributeType = attributeType; this.folder = folder; } } }
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/wizards/ImportCoreSchemasWizard.java
plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/wizards/ImportCoreSchemasWizard.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.wizards; import org.apache.directory.studio.schemaeditor.Activator; import org.apache.directory.studio.schemaeditor.PluginUtils; import org.apache.directory.studio.schemaeditor.controller.SchemaHandler; import org.apache.directory.studio.schemaeditor.model.Project; import org.apache.directory.studio.schemaeditor.model.Schema; import org.apache.directory.studio.schemaeditor.view.widget.CoreSchemasSelectionWidget.ServerTypeEnum; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jface.wizard.Wizard; import org.eclipse.ui.IImportWizard; import org.eclipse.ui.IWorkbench; /** * This class represents the wizard to import 'core' schemas into a project. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class ImportCoreSchemasWizard extends Wizard implements IImportWizard { // The pages of the wizard private ImportCoreSchemasWizardPage page; /** * {@inheritDoc} */ public void addPages() { // Creating pages page = new ImportCoreSchemasWizardPage(); // Adding pages addPage( page ); } /** * {@inheritDoc} */ public boolean performFinish() { String[] selectedSchemas = page.getSelectedSchemas();; ServerTypeEnum serverType = page.getServerType(); Project project = Activator.getDefault().getProjectsHandler().getOpenProject(); if ( project != null ) { if ( ( selectedSchemas != null ) && ( serverType != null ) ) { SchemaHandler schemaHandler = project.getSchemaHandler(); for ( String selectedSchema : selectedSchemas ) { Schema schema = PluginUtils.loadCoreSchema( serverType, selectedSchema ); if ( schema != null ) { schema.setProject( project ); schemaHandler.addSchema( schema ); } } } } return true; } /** * {@inheritDoc} */ public void init( IWorkbench workbench, IStructuredSelection 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/wizards/NewProjectWizard.java
plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/wizards/NewProjectWizard.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.wizards; import java.util.ArrayList; import java.util.List; import org.apache.directory.studio.common.core.jobs.StudioProgressMonitor; import org.apache.directory.studio.connection.core.Connection; import org.apache.directory.studio.connection.core.jobs.StudioConnectionRunnableWithProgress; import org.apache.directory.studio.connection.ui.RunnableContextRunner; 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.ProjectsHandler; import org.apache.directory.studio.schemaeditor.controller.SchemaHandler; 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.apache.directory.studio.schemaeditor.model.io.GenericSchemaConnector; import org.apache.directory.studio.schemaeditor.model.io.SchemaConnector; import org.apache.directory.studio.schemaeditor.view.widget.CoreSchemasSelectionWidget.ServerTypeEnum; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jface.wizard.IWizardPage; import org.eclipse.jface.wizard.Wizard; import org.eclipse.ui.INewWizard; import org.eclipse.ui.IWorkbench; /** * This class represents the wizard to create a new Project. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class NewProjectWizard extends Wizard implements INewWizard { public static final String ID = PluginConstants.NEW_WIZARD_NEW_PROJECT_WIZARD; // The pages of the wizard private NewProjectWizardInformationPage informationPage; private NewProjectWizardConnectionSelectionPage connectionSelectionPage; private NewProjectWizardSchemasSelectionPage schemasSelectionPage; /** * {@inheritDoc} */ public void addPages() { // Creating pages informationPage = new NewProjectWizardInformationPage(); connectionSelectionPage = new NewProjectWizardConnectionSelectionPage(); schemasSelectionPage = new NewProjectWizardSchemasSelectionPage(); // Adding pages addPage( informationPage ); addPage( connectionSelectionPage ); addPage( schemasSelectionPage ); } /** * {@inheritDoc} */ public boolean performFinish() { String projectName = informationPage.getProjectName(); ProjectType projectType = informationPage.getProjectType(); // Creating the project final Project project = new Project( projectType, projectName ); if ( projectType.equals( ProjectType.ONLINE ) ) // Project is an "Online Project" { // Setting the connection to use project.setConnection( connectionSelectionPage.getSelectedConnection() ); RunnableContextRunner.execute( new StudioConnectionRunnableWithProgress() { public void run( StudioProgressMonitor monitor ) { // Getting the correct SchemaConnector for this connection List<SchemaConnector> correctSchemaConnectors = getCorrectSchemaConnectors( project.getConnection(), monitor ); // If no suitable SchemaConnector has been found, we display an // error message and return false; if ( correctSchemaConnectors.size() == 0 ) { monitor.reportError( "No suitable SchemaConnector has been found for the choosen Directory Server.", //$NON-NLS-1$ new NoSuitableSchemaConnectorException() ); } // Check if generic schema connector is included, then remove it to use a specific one if ( correctSchemaConnectors.size() > 1 ) { for ( SchemaConnector schemaConnector : correctSchemaConnectors ) { if ( schemaConnector instanceof GenericSchemaConnector ) { correctSchemaConnectors.remove( schemaConnector ); break; } } } // Getting the correct SchemaConnector SchemaConnector correctSchemaConnector = null; if ( correctSchemaConnectors.size() == 1 ) { correctSchemaConnector = correctSchemaConnectors.get( 0 ); } else { // TODO display a dialog in which the user can select the correct schema connector } project.setSchemaConnector( correctSchemaConnector ); // Fetching the Online Schema project.fetchOnlineSchema( monitor ); } public String getName() { return Messages.getString( "NewProjectWizard.FetchingSchema" ); //$NON-NLS-1$; } public Object[] getLockedObjects() { return null; } public String getErrorMessage() { return Messages.getString( "NewProjectWizard.ErrorWhileFetchingSchema" ); //$NON-NLS-1$; } public Connection[] getConnections() { return null; } }, getContainer(), true ); } else if ( projectType.equals( ProjectType.OFFLINE ) ) // Project is an "Offline Project" { // Getting the selected 'core' schemas String[] selectedSchemas = schemasSelectionPage.getSelectedSchemas(); ServerTypeEnum serverType = schemasSelectionPage.getServerType(); if ( ( selectedSchemas != null ) && ( serverType != null ) ) { SchemaHandler schemaHandler = project.getSchemaHandler(); for ( String selectedSchema : selectedSchemas ) { Schema schema = PluginUtils.loadCoreSchema( serverType, selectedSchema ); if ( schema != null ) { schema.setProject( project ); schemaHandler.addSchema( schema ); } } } } ProjectsHandler projectsHandler = Activator.getDefault().getProjectsHandler(); projectsHandler.addProject( project ); projectsHandler.openProject( project ); return true; } /** * Gets the List of suitable SchemaConnectors * * @param connection * the connection to test the SchemaConnectors with * @return * the List of suitable SchemaConnectors */ private List<SchemaConnector> getCorrectSchemaConnectors( Connection connection, StudioProgressMonitor monitor ) { List<SchemaConnector> suitableSchemaConnectors = new ArrayList<SchemaConnector>(); // Looping on the SchemaConnectors List<SchemaConnector> schemaConectors = PluginUtils.getSchemaConnectors(); for ( SchemaConnector schemaConnector : schemaConectors ) { // Testing if the SchemaConnector is suitable for this connection if ( schemaConnector.isSuitableConnector( connection, monitor ) ) { suitableSchemaConnectors.add( schemaConnector ); } } return suitableSchemaConnectors; } /** * {@inheritDoc} */ public IWizardPage getNextPage( IWizardPage page ) { if ( page.equals( informationPage ) ) { if ( informationPage.getProjectType().equals( ProjectType.ONLINE ) ) { return connectionSelectionPage; } else if ( informationPage.getProjectType().equals( ProjectType.OFFLINE ) ) { return schemasSelectionPage; } } // Default return null; } /** * {@inheritDoc} */ public IWizardPage getPreviousPage( IWizardPage page ) { if ( ( page.equals( connectionSelectionPage ) ) || ( page.equals( schemasSelectionPage ) ) ) { return informationPage; } // Default return null; } /** * {@inheritDoc} */ public boolean canFinish() { IWizardPage currentPage = getContainer().getCurrentPage(); if ( currentPage.equals( informationPage ) ) { return false; } else if ( currentPage.equals( schemasSelectionPage ) ) { return true; } else if ( currentPage.equals( connectionSelectionPage ) ) { return connectionSelectionPage.isPageComplete(); } else { return false; } } /** * {@inheritDoc} */ public void init( IWorkbench workbench, IStructuredSelection selection ) { setNeedsProgressMonitor( true ); } class NoSuitableSchemaConnectorException extends Exception { private static final long serialVersionUID = 1L; } }
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/wizards/ExportSchemasAsXmlWizard.java
plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/wizards/ExportSchemasAsXmlWizard.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.wizards; import java.io.BufferedWriter; import java.io.FileWriter; import java.io.IOException; import java.lang.reflect.InvocationTargetException; import org.apache.directory.studio.schemaeditor.PluginUtils; import org.apache.directory.studio.schemaeditor.model.Schema; import org.apache.directory.studio.schemaeditor.model.io.XMLSchemaFileExporter; import org.apache.directory.studio.schemaeditor.view.ViewUtils; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.jface.operation.IRunnableWithProgress; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jface.wizard.Wizard; import org.eclipse.osgi.util.NLS; import org.eclipse.ui.IExportWizard; import org.eclipse.ui.IWorkbench; /** * This class represents the wizard to export schemas as XML. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class ExportSchemasAsXmlWizard extends Wizard implements IExportWizard { /** The selected schemas */ private Schema[] selectedSchemas = new Schema[0]; // The pages of the wizard private ExportSchemasAsXmlWizardPage page; /** * {@inheritDoc} */ public void addPages() { // Creating pages page = new ExportSchemasAsXmlWizardPage(); page.setSelectedSchemas( selectedSchemas ); // Adding pages addPage( page ); } /** * {@inheritDoc} */ public boolean performFinish() { // Saving the dialog settings page.saveDialogSettings(); // Getting the schemas to be exported and where to export them final Schema[] selectedSchemas = page.getSelectedSchemas(); int exportType = page.getExportType(); if ( exportType == ExportSchemasAsXmlWizardPage.EXPORT_MULTIPLE_FILES ) { final String exportDirectory = page.getExportDirectory(); try { getContainer().run( false, false, new IRunnableWithProgress() { public void run( IProgressMonitor monitor ) { monitor.beginTask( Messages.getString( "ExportSchemasAsXmlWizard.ExportingSchemas" ), selectedSchemas.length ); //$NON-NLS-1$ for ( Schema schema : selectedSchemas ) { monitor.subTask( schema.getSchemaName() ); try { BufferedWriter buffWriter = new BufferedWriter( new FileWriter( exportDirectory + "/" //$NON-NLS-1$ + schema.getSchemaName() + ".xml" ) ); //$NON-NLS-1$ buffWriter.write( XMLSchemaFileExporter.toXml( schema ) ); buffWriter.close(); } catch ( IOException e ) { PluginUtils .logError( NLS .bind( Messages.getString( "ExportSchemasAsXmlWizard.ErrorWhenSavingSchema" ), new String[] { schema.getSchemaName() } ), e ); //$NON-NLS-1$ ViewUtils .displayErrorMessageDialog( Messages.getString( "ExportSchemasAsXmlWizard.Error" ), NLS.bind( Messages.getString( "ExportSchemasAsXmlWizard.ErrorWhenSavingSchema" ), new String[] { schema.getSchemaName() } ) ); //$NON-NLS-1$ //$NON-NLS-2$ } monitor.worked( 1 ); } monitor.done(); } } ); } catch ( InvocationTargetException e ) { // Nothing to do (it will never occur) } catch ( InterruptedException e ) { // Nothing to do. } } else if ( exportType == ExportSchemasAsXmlWizardPage.EXPORT_SINGLE_FILE ) { final String exportFile = page.getExportFile(); try { getContainer().run( false, false, new IRunnableWithProgress() { public void run( IProgressMonitor monitor ) { monitor.beginTask( Messages.getString( "ExportSchemasAsXmlWizard.ExportingSchemas" ), 1 ); //$NON-NLS-1$ try { BufferedWriter buffWriter = new BufferedWriter( new FileWriter( exportFile ) ); buffWriter.write( XMLSchemaFileExporter.toXml( selectedSchemas ) ); buffWriter.close(); } catch ( IOException e ) { PluginUtils.logError( Messages .getString( "ExportSchemasAsXmlWizard.ErrorWhenSavingSchemas" ), e ); //$NON-NLS-1$ ViewUtils .displayErrorMessageDialog( Messages.getString( "ExportSchemasAsXmlWizard.Error" ), Messages.getString( "ExportSchemasAsXmlWizard.ErrorWhenSavingSchemas" ) ); //$NON-NLS-1$ //$NON-NLS-2$ } monitor.worked( 1 ); monitor.done(); } } ); } catch ( InvocationTargetException e ) { // Nothing to do (it will never occur) } catch ( InterruptedException e ) { // Nothing to do. } } return true; } /** * {@inheritDoc} */ public void init( IWorkbench workbench, IStructuredSelection selection ) { setNeedsProgressMonitor( true ); } /** * Sets the selected projects. * * @param schemas * the schemas */ public void setSelectedSchemas( Schema[] schemas ) { selectedSchemas = schemas; } }
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/wizards/NewAttributeTypeContentWizardPage.java
plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/wizards/NewAttributeTypeContentWizardPage.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.wizards; 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.LdapSyntax; 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.controller.SchemaHandler; import org.apache.directory.studio.schemaeditor.view.dialogs.AttributeTypeSelectionDialog; import org.eclipse.jface.dialogs.Dialog; import org.eclipse.jface.viewers.ArrayContentProvider; import org.eclipse.jface.viewers.ComboViewer; import org.eclipse.jface.viewers.LabelProvider; import org.eclipse.jface.viewers.StructuredSelection; import org.eclipse.osgi.util.NLS; 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.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.Group; import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Spinner; import org.eclipse.swt.widgets.Text; /** * This class represents the Content WizardPage of the NewAttributeTypeWizard. * <p> * It is used to let the user enter content information about the * attribute type he wants to create (superior, usage, syntax and properties). * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class NewAttributeTypeContentWizardPage extends AbstractWizardPage { /** The SchemaHandler */ private SchemaHandler schemaHandler; // UI Fields private Text superiorText; private Button superiorButton; private ComboViewer usageComboViewer; private ComboViewer syntaxComboViewer; private Spinner lengthSpinner; private Button obsoleteCheckbox; private Button singleValueCheckbox; private Button collectiveCheckbox; private Button noUserModificationCheckbox; /** * Creates a new instance of NewAttributeTypeContentWizardPage. */ protected NewAttributeTypeContentWizardPage() { super( "NewAttributeTypeContentWizardPage" ); //$NON-NLS-1$ setTitle( Messages.getString( "NewAttributeTypeContentWizardPage.AttributTypeContent" ) ); //$NON-NLS-1$ setDescription( Messages.getString( "NewAttributeTypeContentWizardPage.EnterAttributeTypeContent" ) ); //$NON-NLS-1$ setImageDescriptor( Activator.getDefault().getImageDescriptor( PluginConstants.IMG_ATTRIBUTE_TYPE_NEW_WIZARD ) ); schemaHandler = Activator.getDefault().getSchemaHandler(); } /** * {@inheritDoc} */ public void createControl( Composite parent ) { Composite composite = new Composite( parent, SWT.NULL ); GridLayout layout = new GridLayout(); composite.setLayout( layout ); // Superior and Usage Group Group superiorUsageGroup = new Group( composite, SWT.NONE ); superiorUsageGroup.setText( Messages.getString( "NewAttributeTypeContentWizardPage.SuperiorAndUsage" ) ); //$NON-NLS-1$ superiorUsageGroup.setLayout( new GridLayout( 3, false ) ); superiorUsageGroup.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) ); // Superior Label superiorLabel = new Label( superiorUsageGroup, SWT.NONE ); superiorLabel.setText( Messages.getString( "NewAttributeTypeContentWizardPage.Superior" ) ); //$NON-NLS-1$ superiorText = new Text( superiorUsageGroup, SWT.BORDER ); superiorText.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) ); superiorText.addModifyListener( new ModifyListener() { public void modifyText( ModifyEvent arg0 ) { verifySuperior(); } } ); superiorButton = new Button( superiorUsageGroup, SWT.PUSH ); superiorButton.setText( Messages.getString( "NewAttributeTypeContentWizardPage.Choose" ) ); //$NON-NLS-1$ superiorButton.setLayoutData( new GridData( SWT.NONE, SWT.NONE, false, false ) ); superiorButton.addSelectionListener( new SelectionAdapter() { public void widgetSelected( SelectionEvent arg0 ) { AttributeTypeSelectionDialog dialog = new AttributeTypeSelectionDialog(); if ( dialog.open() == Dialog.OK ) { AttributeType selectedAT = dialog.getSelectedAttributeType(); List<String> aliases = selectedAT.getNames(); if ( ( aliases != null ) && ( aliases.size() > 0 ) ) { superiorText.setText( aliases.get( 0 ) ); } else { superiorText.setText( selectedAT.getOid() ); } } } } ); // Usage Label usageLabel = new Label( superiorUsageGroup, SWT.NONE ); usageLabel.setText( Messages.getString( "NewAttributeTypeContentWizardPage.Usage" ) ); //$NON-NLS-1$ Combo usageCombo = new Combo( superiorUsageGroup, SWT.READ_ONLY ); usageCombo.setLayoutData( new GridData( SWT.NONE, SWT.NONE, false, false, 2, 1 ) ); usageComboViewer = new ComboViewer( usageCombo ); usageComboViewer.setLabelProvider( new LabelProvider() ); usageComboViewer.setContentProvider( new ArrayContentProvider() ); usageComboViewer .setInput( new String[] { Messages.getString( "NewAttributeTypeContentWizardPage.DirectoryOperation" ), Messages.getString( "NewAttributeTypeContentWizardPage.DistributedOperation" ), Messages.getString( "NewAttributeTypeContentWizardPage.DSAOperation" ), Messages.getString( "NewAttributeTypeContentWizardPage.UserApplications" ) } ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ usageComboViewer.setSelection( new StructuredSelection( Messages .getString( "NewAttributeTypeContentWizardPage.UserApplications" ) ) ); //$NON-NLS-1$ // Syntax Group Group syntaxGroup = new Group( composite, SWT.NONE ); syntaxGroup.setText( Messages.getString( "NewAttributeTypeContentWizardPage.Syntax" ) ); //$NON-NLS-1$ syntaxGroup.setLayout( new GridLayout( 2, false ) ); syntaxGroup.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) ); // Syntax Label syntaxLabel = new Label( syntaxGroup, SWT.NONE ); syntaxLabel.setText( Messages.getString( "NewAttributeTypeContentWizardPage.SyntaxColon" ) ); //$NON-NLS-1$ Combo syntaxCombo = new Combo( syntaxGroup, SWT.READ_ONLY ); syntaxCombo.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) ); syntaxComboViewer = new ComboViewer( syntaxCombo ); syntaxComboViewer.setContentProvider( new ArrayContentProvider() ); syntaxComboViewer.setLabelProvider( new LabelProvider() { public String getText( Object element ) { if ( element instanceof LdapSyntax ) { LdapSyntax syntax = ( LdapSyntax ) element; // Getting description (and name for backward compatibility) String description = syntax.getDescription(); String name = syntax.getName(); if ( ( description != null ) || ( name != null ) ) { if ( description != null ) { // Using description return NLS .bind( Messages.getString( "NewAttributeTypeContentWizardPage.NameOID" ), new String[] { description, syntax.getOid() } ); //$NON-NLS-1$ } else { // Using name (for backward compatibility) return NLS .bind( Messages.getString( "NewAttributeTypeContentWizardPage.NameOID" ), new String[] { name, syntax.getOid() } ); //$NON-NLS-1$ } } else { return NLS .bind( Messages.getString( "NewAttributeTypeContentWizardPage.NoneOID" ), new String[] { syntax.getOid() } ); //$NON-NLS-1$ } } return super.getText( element ); } } ); // Syntax Length Label lengthLabel = new Label( syntaxGroup, SWT.NONE ); lengthLabel.setText( Messages.getString( "NewAttributeTypeContentWizardPage.Length" ) ); //$NON-NLS-1$ lengthSpinner = new Spinner( syntaxGroup, SWT.BORDER ); lengthSpinner.setIncrement( 1 ); lengthSpinner.setMinimum( 0 ); lengthSpinner.setMaximum( Integer.MAX_VALUE ); GridData lengthSpinnerGridData = new GridData( SWT.NONE, SWT.NONE, false, false ); lengthSpinnerGridData.widthHint = 42; lengthSpinner.setLayoutData( lengthSpinnerGridData ); // Properties Group Group propertiesGroup = new Group( composite, SWT.NONE ); propertiesGroup.setText( Messages.getString( "NewAttributeTypeContentWizardPage.Properties" ) ); //$NON-NLS-1$ propertiesGroup.setLayout( new GridLayout() ); propertiesGroup.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) ); // Obsolete new Label( composite, SWT.NONE ); obsoleteCheckbox = new Button( propertiesGroup, SWT.CHECK ); obsoleteCheckbox.setText( Messages.getString( "NewAttributeTypeContentWizardPage.Obsolete" ) ); //$NON-NLS-1$ // Single value new Label( composite, SWT.NONE ); singleValueCheckbox = new Button( propertiesGroup, SWT.CHECK ); singleValueCheckbox.setText( Messages.getString( "NewAttributeTypeContentWizardPage.SingleValue" ) ); //$NON-NLS-1$ // Collective new Label( composite, SWT.NONE ); collectiveCheckbox = new Button( propertiesGroup, SWT.CHECK ); collectiveCheckbox.setText( Messages.getString( "NewAttributeTypeContentWizardPage.Collective" ) ); //$NON-NLS-1$ // No User Modification new Label( composite, SWT.NONE ); noUserModificationCheckbox = new Button( propertiesGroup, SWT.CHECK ); noUserModificationCheckbox .setText( Messages.getString( "NewAttributeTypeContentWizardPage.NoUserModifcation" ) ); //$NON-NLS-1$ initFields(); setControl( composite ); } /** * Initializes the UI fields. */ private void initFields() { if ( schemaHandler != null ) { // Getting the syntaxes List<Object> syntaxes = new ArrayList<Object>( schemaHandler.getSyntaxes() ); // Adding the (None) Syntax String none = Messages.getString( "NewAttributeTypeContentWizardPage.None" ); //$NON-NLS-1$ syntaxes.add( none ); // Sorting the syntaxes Collections.sort( syntaxes, new Comparator<Object>() { public int compare( Object o1, Object o2 ) { if ( ( o1 instanceof LdapSyntax ) && ( o2 instanceof LdapSyntax ) ) { String o1description = ( ( LdapSyntax ) o1 ).getDescription(); String o2description = ( ( LdapSyntax ) o2 ).getDescription(); String o1Name = ( ( LdapSyntax ) o1 ).getName(); String o2Name = ( ( LdapSyntax ) o2 ).getName(); // Comparing by description if ( ( o1description != null ) && ( o2description != null ) ) { return o1description.compareToIgnoreCase( o2description ); } // Comparing by name else if ( ( o1Name != null ) && ( o2Name != null ) ) { return o1Name.compareToIgnoreCase( o2Name ); } } else if ( ( o1 instanceof String ) && ( o2 instanceof LdapSyntax ) ) { return Integer.MIN_VALUE; } else if ( ( o1 instanceof LdapSyntax ) && ( o2 instanceof String ) ) { return Integer.MAX_VALUE; } // Default return o1.toString().compareToIgnoreCase( o2.toString() ); } } ); // Setting the input syntaxComboViewer.setInput( syntaxes ); syntaxComboViewer.setSelection( new StructuredSelection( none ) ); } } /** * Verifies if the superior exists and displays an error if not. */ private void verifySuperior() { String superior = superiorText.getText(); if ( ( superior != null ) && ( !superior.equals( "" ) ) ) //$NON-NLS-1$ { if ( schemaHandler.getAttributeType( superiorText.getText() ) == null ) { displayErrorMessage( Messages .getString( "NewAttributeTypeContentWizardPage.ErrorSuperiorAttributeTypeNotExists" ) ); //$NON-NLS-1$ return; } } displayErrorMessage( null ); } /** * Gets the superior value. * * @return * the superior value */ public String getSuperiorValue() { String superior = superiorText.getText(); if ( ( superior != null ) && ( !superior.equals( "" ) ) ) //$NON-NLS-1$ { return superior; } else { return null; } } /** * Gets the usage value. * * @return * the usage value */ public UsageEnum getUsageValue() { StructuredSelection selection = ( StructuredSelection ) usageComboViewer.getSelection(); if ( !selection.isEmpty() ) { String selectedUsage = ( String ) selection.getFirstElement(); if ( selectedUsage.equals( Messages.getString( "NewAttributeTypeContentWizardPage.DirectoryOperation" ) ) ) //$NON-NLS-1$ { return UsageEnum.DIRECTORY_OPERATION; } else if ( selectedUsage.equals( Messages .getString( "NewAttributeTypeContentWizardPage.DistributedOperation" ) ) ) //$NON-NLS-1$ { return UsageEnum.DISTRIBUTED_OPERATION; } else if ( selectedUsage.equals( Messages.getString( "NewAttributeTypeContentWizardPage.DSAOperation" ) ) ) //$NON-NLS-1$ { return UsageEnum.DSA_OPERATION; } else if ( selectedUsage.equals( Messages.getString( "NewAttributeTypeContentWizardPage.UserApplications" ) ) ) //$NON-NLS-1$ { return UsageEnum.USER_APPLICATIONS; } else { return UsageEnum.USER_APPLICATIONS; } } else { return UsageEnum.USER_APPLICATIONS; } } /** * Gets the syntax value. * * @return * the syntax value */ public String getSyntax() { Object selection = ( ( StructuredSelection ) syntaxComboViewer.getSelection() ).getFirstElement(); if ( selection instanceof LdapSyntax ) { return ( ( LdapSyntax ) selection ).getOid(); } return null; } /** * Gets the syntax length value. * * @return * the syntax length value */ public int getSyntaxLengthValue() { return lengthSpinner.getSelection(); } /** * Gets the 'Obsolete' value. * * @return * the 'Obsolete' value */ public boolean getObsoleteValue() { return obsoleteCheckbox.getSelection(); } /** * Gets the 'Single Value' value * * @return * the 'Single Value' value */ public boolean getSingleValueValue() { return singleValueCheckbox.getSelection(); } /** * Gets the 'Collective' value. * * @return * the 'Collective' value */ public boolean getCollectiveValue() { return collectiveCheckbox.getSelection(); } /** * Gets the 'No User Modification' value. * * @return * the 'No User Modification' value */ public boolean getNoUserModificationValue() { return noUserModificationCheckbox.getSelection(); } }
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/wizards/NewObjectClassContentWizardPage.java
plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/wizards/NewObjectClassContentWizardPage.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.wizards; 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.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.view.ViewUtils; import org.apache.directory.studio.schemaeditor.view.dialogs.ObjectClassSelectionDialog; import org.eclipse.jface.dialogs.Dialog; import org.eclipse.jface.viewers.ArrayContentProvider; import org.eclipse.jface.viewers.ISelectionChangedListener; import org.eclipse.jface.viewers.LabelProvider; import org.eclipse.jface.viewers.SelectionChangedEvent; import org.eclipse.jface.viewers.StructuredSelection; import org.eclipse.jface.viewers.TableViewer; import org.eclipse.jface.wizard.WizardPage; import org.eclipse.osgi.util.NLS; import org.eclipse.swt.SWT; 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.Group; import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Table; /** * This class represents the Content WizardPage of the ObjectClassWizard. * <p> * It is used to let the user enter content information about the * attribute type he wants to create (superiors, class type, and properties). * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class NewObjectClassContentWizardPage extends WizardPage { /** The superiors object classes */ private List<ObjectClass> superiorsList; /** The type of the object class */ private ObjectClassTypeEnum type = ObjectClassTypeEnum.STRUCTURAL; // UI Fields private TableViewer superiorsTableViewer; private Button superiorsAddButton; private Button superiorsRemoveButton; private Button structuralRadio; private Button abstractRadio; private Button auxiliaryRadio; private Button obsoleteCheckbox; /** * Creates a new instance of NewAttributeTypeContentWizardPage. */ protected NewObjectClassContentWizardPage() { super( "NewObjectClassContentWizardPage" ); //$NON-NLS-1$ setTitle( Messages.getString( "NewObjectClassContentWizardPage.ObjectClassContent" ) ); //$NON-NLS-1$ setDescription( Messages.getString( "NewObjectClassContentWizardPage.EnterObjectClassContent" ) ); //$NON-NLS-1$ setImageDescriptor( Activator.getDefault().getImageDescriptor( PluginConstants.IMG_OBJECT_CLASS_NEW_WIZARD ) ); superiorsList = new ArrayList<ObjectClass>(); } /** * {@inheritDoc} */ public void createControl( Composite parent ) { Composite composite = new Composite( parent, SWT.NULL ); GridLayout layout = new GridLayout(); composite.setLayout( layout ); // Superiors Group superiorsGroup = new Group( composite, SWT.NONE ); superiorsGroup.setText( Messages.getString( "NewObjectClassContentWizardPage.Superiors" ) ); //$NON-NLS-1$ superiorsGroup.setLayout( new GridLayout( 2, false ) ); superiorsGroup.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) ); // Superiors Table superiorsTable = new Table( superiorsGroup, SWT.BORDER ); GridData superiorsTableGridData = new GridData( SWT.FILL, SWT.FILL, true, true, 1, 2 ); superiorsTableGridData.heightHint = 100; superiorsTable.setLayoutData( superiorsTableGridData ); superiorsTableViewer = new TableViewer( superiorsTable ); superiorsTableViewer.setLabelProvider( new LabelProvider() { public Image getImage( Object element ) { if ( element instanceof ObjectClass ) { return Activator.getDefault().getImage( PluginConstants.IMG_OBJECT_CLASS ); } // Default return super.getImage( element ); } public String getText( Object element ) { if ( element instanceof ObjectClass ) { ObjectClass oc = ( ObjectClass ) element; List<String> names = oc.getNames(); if ( ( names != null ) && ( names.size() > 0 ) ) { return NLS .bind( Messages.getString( "NewObjectClassContentWizardPage.AliasOID" ), new String[] { ViewUtils.concateAliases( names ), oc.getOid() } ); //$NON-NLS-1$ } else { return NLS .bind( Messages.getString( "NewObjectClassContentWizardPage.NoneOID" ), new String[] { oc.getOid() } ); //$NON-NLS-1$ } } // Default return super.getText( element ); } } ); superiorsTableViewer.setContentProvider( new ArrayContentProvider() ); superiorsTableViewer.setInput( superiorsList ); superiorsTableViewer.addSelectionChangedListener( new ISelectionChangedListener() { public void selectionChanged( SelectionChangedEvent event ) { superiorsRemoveButton.setEnabled( !event.getSelection().isEmpty() ); } } ); superiorsAddButton = new Button( superiorsGroup, SWT.PUSH ); superiorsAddButton.setText( Messages.getString( "NewObjectClassContentWizardPage.Add" ) ); //$NON-NLS-1$ superiorsAddButton.setLayoutData( new GridData( SWT.FILL, SWT.NONE, false, false ) ); superiorsAddButton.addSelectionListener( new SelectionAdapter() { public void widgetSelected( SelectionEvent arg0 ) { addSuperiorObjectClass(); } } ); superiorsRemoveButton = new Button( superiorsGroup, SWT.PUSH ); superiorsRemoveButton.setText( Messages.getString( "NewObjectClassContentWizardPage.Remove" ) ); //$NON-NLS-1$ superiorsRemoveButton.setLayoutData( new GridData( SWT.FILL, SWT.NONE, false, false ) ); superiorsRemoveButton.setEnabled( false ); superiorsRemoveButton.addSelectionListener( new SelectionAdapter() { public void widgetSelected( SelectionEvent arg0 ) { removeSuperiorObjectClass(); } } ); // Class Type Group Group classTypeGroup = new Group( composite, SWT.NONE ); classTypeGroup.setText( Messages.getString( "NewObjectClassContentWizardPage.ClassType" ) ); //$NON-NLS-1$ classTypeGroup.setLayout( new GridLayout( 5, false ) ); classTypeGroup.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) ); // Class Type Label classTypeLable = new Label( classTypeGroup, SWT.NONE ); classTypeLable.setText( Messages.getString( "NewObjectClassContentWizardPage.ClassTypeColon" ) ); //$NON-NLS-1$ new Label( classTypeGroup, SWT.NONE ).setText( " " ); //$NON-NLS-1$ structuralRadio = new Button( classTypeGroup, SWT.RADIO ); structuralRadio.setText( Messages.getString( "NewObjectClassContentWizardPage.Structural" ) ); //$NON-NLS-1$ GridData structuralRadioGridData = new GridData( SWT.LEFT, SWT.NONE, false, false ); structuralRadioGridData.widthHint = 115; structuralRadio.setLayoutData( structuralRadioGridData ); structuralRadio.addSelectionListener( new SelectionAdapter() { public void widgetSelected( SelectionEvent arg0 ) { type = ObjectClassTypeEnum.STRUCTURAL; } } ); structuralRadio.setSelection( true ); abstractRadio = new Button( classTypeGroup, SWT.RADIO ); abstractRadio.setText( Messages.getString( "NewObjectClassContentWizardPage.Abstract" ) ); //$NON-NLS-1$ GridData abstractRadioGridData = new GridData( SWT.LEFT, SWT.NONE, false, false ); abstractRadioGridData.widthHint = 115; abstractRadio.setLayoutData( structuralRadioGridData ); abstractRadio.addSelectionListener( new SelectionAdapter() { public void widgetSelected( SelectionEvent arg0 ) { type = ObjectClassTypeEnum.ABSTRACT; } } ); auxiliaryRadio = new Button( classTypeGroup, SWT.RADIO ); auxiliaryRadio.setText( Messages.getString( "NewObjectClassContentWizardPage.Auxiliary" ) ); //$NON-NLS-1$ GridData auxiliaryRadioGridData = new GridData( SWT.LEFT, SWT.NONE, false, false ); auxiliaryRadioGridData.widthHint = 115; auxiliaryRadio.setLayoutData( structuralRadioGridData ); auxiliaryRadio.addSelectionListener( new SelectionAdapter() { public void widgetSelected( SelectionEvent arg0 ) { type = ObjectClassTypeEnum.AUXILIARY; } } ); // Properties Group Group propertiesGroup = new Group( composite, SWT.NONE ); propertiesGroup.setText( Messages.getString( "NewObjectClassContentWizardPage.Properties" ) ); //$NON-NLS-1$ propertiesGroup.setLayout( new GridLayout() ); propertiesGroup.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) ); // Obsolete obsoleteCheckbox = new Button( propertiesGroup, SWT.CHECK ); obsoleteCheckbox.setText( Messages.getString( "NewObjectClassContentWizardPage.Obsolete" ) ); //$NON-NLS-1$ setControl( composite ); } /** * This method is called when the "Add" button of the superiors * table is selected. */ private void addSuperiorObjectClass() { ObjectClassSelectionDialog dialog = new ObjectClassSelectionDialog(); dialog.setHiddenObjectClasses( superiorsList ); if ( dialog.open() == Dialog.OK ) { superiorsList.add( dialog.getSelectedObjectClass() ); updateSuperiorsTable(); } } /** * This method is called when the "Remove" button of the superiors * table is selected. */ private void removeSuperiorObjectClass() { StructuredSelection selection = ( StructuredSelection ) superiorsTableViewer.getSelection(); if ( !selection.isEmpty() ) { superiorsList.remove( selection.getFirstElement() ); updateSuperiorsTable(); } } /** * Updates the superiors table */ private void updateSuperiorsTable() { Collections.sort( superiorsList, new Comparator<ObjectClass>() { public int compare( ObjectClass o1, ObjectClass o2 ) { List<String> at1Names = o1.getNames(); List<String> at2Names = o2.getNames(); if ( ( at1Names != null ) && ( at2Names != null ) && ( at1Names.size() > 0 ) && ( at2Names.size() > 0 ) ) { return at1Names.get( 0 ).compareToIgnoreCase( at2Names.get( 0 ) ); } // Default return 0; } } ); superiorsTableViewer.refresh(); } /** * Gets the value of the superiors. * * @return * the value of the superiors */ public List<String> getSuperiorsNameValue() { List<String> names = new ArrayList<String>(); for ( ObjectClass oc : superiorsList ) { List<String> aliases = oc.getNames(); if ( ( aliases != null ) && ( aliases.size() > 0 ) ) { names.add( aliases.get( 0 ) ); } else { names.add( oc.getOid() ); } } return names; } /** * Gets the class type value. * * @return * the class type value */ public ObjectClassTypeEnum getClassTypeValue() { return type; } /** * Gets the 'Obsolete' value. * * @return * the 'Obsolete' value */ public boolean getObsoleteValue() { return obsoleteCheckbox.getSelection(); } }
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/wizards/NewProjectWizardInformationPage.java
plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/wizards/NewProjectWizardInformationPage.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.wizards; 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.ProjectsHandler; import org.apache.directory.studio.schemaeditor.model.ProjectType; 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.SelectionListener; 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.Group; import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Text; /** * This class represents the Information Page of the NewProjectWizard. * <p> * It is used to let the user create a new Project * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class NewProjectWizardInformationPage extends AbstractWizardPage { /** The ProjectsHandler */ private ProjectsHandler projectsHandler; // UI Fields private Text nameText; private Button typeOnlineRadio; private Button typeOfflineRadio; /** * Creates a new instance of NewProjectWizardInformationPage. */ protected NewProjectWizardInformationPage() { super( "NewProjectWizardInformationPage" ); //$NON-NLS-1$ setTitle( Messages.getString( "NewProjectWizardInformationPage.CreateSchemaProject" ) ); //$NON-NLS-1$ setDescription( Messages.getString( "NewProjectWizardInformationPage.SpecifiyNameAndType" ) ); //$NON-NLS-1$ setImageDescriptor( Activator.getDefault().getImageDescriptor( PluginConstants.IMG_PROJECT_NEW_WIZARD ) ); projectsHandler = Activator.getDefault().getProjectsHandler(); } /** * {@inheritDoc} */ public void createControl( Composite parent ) { Composite composite = new Composite( parent, SWT.NULL ); GridLayout layout = new GridLayout( 2, false ); composite.setLayout( layout ); // Name Label nameLabel = new Label( composite, SWT.NONE ); nameLabel.setText( Messages.getString( "NewProjectWizardInformationPage.ProjectName" ) ); //$NON-NLS-1$ nameText = new Text( composite, SWT.BORDER ); nameText.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) ); if ( PluginUtils.getSchemaConnectors().size() > 0 ) { // Type Group Group typeGroup = new Group( composite, SWT.NONE ); typeGroup.setText( Messages.getString( "NewProjectWizardInformationPage.Type" ) ); //$NON-NLS-1$ typeGroup.setLayout( new GridLayout() ); typeGroup.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false, 2, 1 ) ); typeOfflineRadio = new Button( typeGroup, SWT.RADIO ); typeOfflineRadio.setText( Messages.getString( "NewProjectWizardInformationPage.OfflineSchema" ) ); //$NON-NLS-1$ typeOfflineRadio.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) ); typeOnlineRadio = new Button( typeGroup, SWT.RADIO ); typeOnlineRadio.setText( Messages.getString( "NewProjectWizardInformationPage.OnlineSchema" ) ); //$NON-NLS-1$ typeOnlineRadio.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) ); } initFields(); addListeners(); setControl( composite ); } /** * Initializes the UI Fields. */ private void initFields() { if ( typeOfflineRadio != null ) { typeOfflineRadio.setSelection( true ); } displayErrorMessage( null ); setPageComplete( false ); } /** * Adds the listeners. */ private void addListeners() { nameText.addModifyListener( new ModifyListener() { public void modifyText( ModifyEvent e ) { dialogChanged(); } } ); SelectionListener dialogChangedSelectionListener = new SelectionAdapter() { public void widgetSelected( SelectionEvent e ) { dialogChanged(); } }; typeOfflineRadio.addSelectionListener( dialogChangedSelectionListener ); typeOnlineRadio.addSelectionListener( dialogChangedSelectionListener ); } /** * This method is called when the user modifies something in the UI. */ private void dialogChanged() { // Name if ( nameText.getText().equals( "" ) ) //$NON-NLS-1$ { displayErrorMessage( Messages.getString( "NewProjectWizardInformationPage.ErrorNoNameSpecified" ) ); //$NON-NLS-1$ return; } else if ( projectsHandler.isProjectNameAlreadyTaken( nameText.getText() ) ) { displayErrorMessage( Messages.getString( "NewProjectWizardInformationPage.ErrorProjectNameExists" ) ); //$NON-NLS-1$ return; } displayErrorMessage( null ); } /** * Gets the name of the project. * * @return * the name of the project */ public String getProjectName() { return nameText.getText(); } /** * Gets the type of the project. * * @return * the type of the project */ public ProjectType getProjectType() { if ( typeOnlineRadio != null ) { if ( typeOnlineRadio.getSelection() ) { return ProjectType.ONLINE; } else { return ProjectType.OFFLINE; } } // Default return ProjectType.OFFLINE; } }
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/wizards/NewAttributeTypeGeneralWizardPage.java
plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/wizards/NewAttributeTypeGeneralWizardPage.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.wizards; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.List; import org.apache.directory.api.asn1.util.Oid; 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.model.Schema; import org.apache.directory.studio.schemaeditor.model.alias.Alias; import org.apache.directory.studio.schemaeditor.model.alias.AliasWithPartError; import org.apache.directory.studio.schemaeditor.model.alias.AliasWithStartError; import org.apache.directory.studio.schemaeditor.model.alias.AliasesStringParser; import org.apache.directory.studio.schemaeditor.view.dialogs.EditAttributeTypeAliasesDialog; import org.eclipse.jface.viewers.ArrayContentProvider; import org.eclipse.jface.viewers.ComboViewer; import org.eclipse.jface.viewers.ISelectionChangedListener; import org.eclipse.jface.viewers.LabelProvider; import org.eclipse.jface.viewers.SelectionChangedEvent; import org.eclipse.jface.viewers.StructuredSelection; import org.eclipse.osgi.util.NLS; 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.Group; import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Text; /** * This class represents the General WizardPage of the NewAttributeTypeWizard. * <p> * It is used to let the user enter general information about the * attribute type he wants to create (schema, OID, aliases an description). * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class NewAttributeTypeGeneralWizardPage extends AbstractWizardPage { /** The SchemaHandler */ private SchemaHandler schemaHandler; /** The aliases */ private List<Alias> aliases; /** The selected schema */ private Schema selectedSchema; // UI fields private ComboViewer schemaComboViewer; private Combo oidCombo; private Text aliasesText; private Button aliasesButton; private Text descriptionText; /** * Creates a new instance of NewAttributeTypeGeneralWizardPage. */ protected NewAttributeTypeGeneralWizardPage() { super( "NewAttributeTypeGeneralWizardPage" ); //$NON-NLS-1$ setTitle( Messages.getString( "NewAttributeTypeGeneralWizardPage.AttributeType" ) ); //$NON-NLS-1$ setDescription( Messages.getString( "NewAttributeTypeGeneralWizardPage.CreateNewAttributeType" ) ); //$NON-NLS-1$ setImageDescriptor( Activator.getDefault().getImageDescriptor( PluginConstants.IMG_ATTRIBUTE_TYPE_NEW_WIZARD ) ); schemaHandler = Activator.getDefault().getSchemaHandler(); aliases = new ArrayList<Alias>(); } /** * {@inheritDoc} */ public void createControl( Composite parent ) { Composite composite = new Composite( parent, SWT.NULL ); GridLayout layout = new GridLayout(); composite.setLayout( layout ); // Schema Group Group schemaGroup = new Group( composite, SWT.NONE ); schemaGroup.setText( Messages.getString( "NewAttributeTypeGeneralWizardPage.Schema" ) ); //$NON-NLS-1$ schemaGroup.setLayout( new GridLayout( 2, false ) ); schemaGroup.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) ); // Schema Label schemaLabel = new Label( schemaGroup, SWT.NONE ); schemaLabel.setText( Messages.getString( "NewAttributeTypeGeneralWizardPage.SchemaColon" ) ); //$NON-NLS-1$ Combo schemaCombo = new Combo( schemaGroup, SWT.READ_ONLY ); schemaCombo.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) ); schemaComboViewer = new ComboViewer( schemaCombo ); schemaComboViewer.setContentProvider( new ArrayContentProvider() ); schemaComboViewer.setLabelProvider( new LabelProvider() { /** * {@inheritDoc} */ public String getText( Object element ) { if ( element instanceof Schema ) { return ( ( Schema ) element ).getSchemaName(); } // Default return super.getText( element ); } } ); schemaComboViewer.addSelectionChangedListener( new ISelectionChangedListener() { /** * {@inheritDoc} */ public void selectionChanged( SelectionChangedEvent event ) { dialogChanged(); } } ); // Naming and Description Group Group namingDescriptionGroup = new Group( composite, SWT.NONE ); namingDescriptionGroup.setText( Messages.getString( "NewAttributeTypeGeneralWizardPage.NamingAndDescription" ) ); //$NON-NLS-1$ namingDescriptionGroup.setLayout( new GridLayout( 3, false ) ); namingDescriptionGroup.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) ); // OID Label oidLabel = new Label( namingDescriptionGroup, SWT.NONE ); oidLabel.setText( Messages.getString( "NewAttributeTypeGeneralWizardPage.OID" ) ); //$NON-NLS-1$ oidCombo = new Combo( namingDescriptionGroup, SWT.DROP_DOWN | SWT.BORDER ); oidCombo.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false, 2, 1 ) ); oidCombo.addModifyListener( new ModifyListener() { /** * {@inheritDoc} */ public void modifyText( ModifyEvent arg0 ) { dialogChanged(); } } ); oidCombo.addVerifyListener( new VerifyListener() { /** * {@inheritDoc} */ public void verifyText( VerifyEvent e ) { if ( !e.text.matches( "([0-9]*\\.?)*" ) ) //$NON-NLS-1$ { e.doit = false; } } } ); oidCombo.setItems( PluginUtils.loadDialogSettingsHistory( PluginConstants.DIALOG_SETTINGS_OID_HISTORY ) ); // Aliases Label aliasesLabel = new Label( namingDescriptionGroup, SWT.NONE ); aliasesLabel.setText( Messages.getString( "NewAttributeTypeGeneralWizardPage.Aliases" ) ); //$NON-NLS-1$ aliasesText = new Text( namingDescriptionGroup, SWT.BORDER ); aliasesText.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) ); aliasesText.addModifyListener( new ModifyListener() { public void modifyText( ModifyEvent e ) { AliasesStringParser parser = new AliasesStringParser(); parser.parse( aliasesText.getText() ); List<Alias> parsedAliases = parser.getAliases(); aliases.clear(); for ( Alias parsedAlias : parsedAliases ) { aliases.add( parsedAlias ); } dialogChanged(); } } ); aliasesButton = new Button( namingDescriptionGroup, SWT.PUSH ); aliasesButton.setText( Messages.getString( "NewAttributeTypeGeneralWizardPage.Edit" ) ); //$NON-NLS-1$ aliasesButton.addSelectionListener( new SelectionAdapter() { /** * {@inheritDoc} */ public void widgetSelected( SelectionEvent arg0 ) { EditAttributeTypeAliasesDialog dialog = new EditAttributeTypeAliasesDialog( getAliasesValue() ); if ( dialog.open() == EditAttributeTypeAliasesDialog.OK ) { String[] newAliases = dialog.getAliases(); StringBuffer sb = new StringBuffer(); for ( String newAlias : newAliases ) { sb.append( newAlias ); sb.append( ", " ); //$NON-NLS-1$ } sb.deleteCharAt( sb.length() - 1 ); sb.deleteCharAt( sb.length() - 1 ); AliasesStringParser parser = new AliasesStringParser(); parser.parse( sb.toString() ); List<Alias> parsedAliases = parser.getAliases(); aliases.clear(); for ( Alias parsedAlias : parsedAliases ) { aliases.add( parsedAlias ); } fillInAliasesLabel(); dialogChanged(); } } } ); // Description Label descriptionLabel = new Label( namingDescriptionGroup, SWT.NONE ); descriptionLabel.setText( Messages.getString( "NewAttributeTypeGeneralWizardPage.Description" ) ); //$NON-NLS-1$ descriptionText = new Text( namingDescriptionGroup, SWT.MULTI | SWT.BORDER | SWT.V_SCROLL ); GridData descriptionGridData = new GridData( SWT.FILL, SWT.NONE, true, false, 2, 1 ); descriptionGridData.heightHint = 67; descriptionText.setLayoutData( descriptionGridData ); descriptionText.addModifyListener( new ModifyListener() { /** * {@inheritDoc} */ public void modifyText( ModifyEvent arg0 ) { dialogChanged(); } } ); initFields(); setControl( composite ); } /** * Initializes the UI fields. */ private void initFields() { if ( schemaHandler == null ) { schemaComboViewer.getCombo().setEnabled( false ); oidCombo.setEnabled( false ); aliasesText.setEnabled( false ); aliasesButton.setEnabled( false ); descriptionText.setEnabled( false ); displayErrorMessage( Messages.getString( "NewAttributeTypeGeneralWizardPage.ErrorNoSchemaProjectOpen" ) ); //$NON-NLS-1$ } else { // Filling the Schemas table List<Schema> schemas = new ArrayList<Schema>(); schemas.addAll( schemaHandler.getSchemas() ); Collections.sort( schemas, new Comparator<Schema>() { public int compare( Schema o1, Schema o2 ) { return o1.getSchemaName().compareToIgnoreCase( o2.getSchemaName() ); } } ); schemaComboViewer.setInput( schemas ); if ( selectedSchema != null ) { schemaComboViewer.setSelection( new StructuredSelection( selectedSchema ) ); } displayErrorMessage( null ); } setPageComplete( false ); } /** * This method is called when the user modifies something in the UI. */ private void dialogChanged() { if ( schemaComboViewer.getSelection().isEmpty() ) { displayErrorMessage( Messages.getString( "NewAttributeTypeGeneralWizardPage.ErrorNoSchemaSpecified" ) ); //$NON-NLS-1$ return; } if ( oidCombo.getText().equals( "" ) ) //$NON-NLS-1$ { displayErrorMessage( Messages.getString( "NewAttributeTypeGeneralWizardPage.ErrorNoOIDSpecified" ) ); //$NON-NLS-1$ return; } if ( ( !oidCombo.getText().equals( "" ) ) && ( !Oid.isOid( oidCombo.getText() ) ) ) //$NON-NLS-1$ { displayErrorMessage( Messages.getString( "NewAttributeTypeGeneralWizardPage.ErrorIncorrectOID" ) ); //$NON-NLS-1$ return; } if ( ( !oidCombo.getText().equals( "" ) ) && ( Oid.isOid( oidCombo.getText() ) ) //$NON-NLS-1$ && ( schemaHandler.isOidAlreadyTaken( oidCombo.getText() ) ) ) { displayErrorMessage( Messages.getString( "NewAttributeTypeGeneralWizardPage.ErrorObjectOIDExists" ) ); //$NON-NLS-1$ return; } if ( aliases.size() == 0 ) { displayWarningMessage( Messages.getString( "NewAttributeTypeGeneralWizardPage.ErrorAttributeTypeNoName" ) ); //$NON-NLS-1$ return; } else { for ( Alias alias : aliases ) { if ( alias instanceof AliasWithStartError ) { displayErrorMessage( NLS .bind( Messages.getString( "NewAttributeTypeGeneralWizardPage.AliasStartInvalid" ), new Object[] { alias, ( ( AliasWithStartError ) alias ).getErrorChar() } ) ); //$NON-NLS-1$ return; } else if ( alias instanceof AliasWithPartError ) { displayErrorMessage( NLS .bind( Messages.getString( "NewAttributeTypeGeneralWizardPage.AliasPartInvalid" ), new Object[] { alias, ( ( AliasWithPartError ) alias ).getErrorChar() } ) ); //$NON-NLS-1$ return; } } } displayErrorMessage( null ); } /** * Fills in the Aliases Label. */ private void fillInAliasesLabel() { StringBuffer sb = new StringBuffer(); for ( Alias alias : aliases ) { sb.append( alias ); sb.append( ", " ); //$NON-NLS-1$ } sb.deleteCharAt( sb.length() - 1 ); sb.deleteCharAt( sb.length() - 1 ); aliasesText.setText( sb.toString() ); } /** * Get the name of the schema. * * @return * the name of the schema */ public String getSchemaValue() { StructuredSelection selection = ( StructuredSelection ) schemaComboViewer.getSelection(); if ( !selection.isEmpty() ) { Schema schema = ( Schema ) selection.getFirstElement(); return schema.getSchemaName(); } else { return null; } } /** * Gets the value of the OID. * * @return * the value of the OID */ public String getOidValue() { return oidCombo.getText(); } /** * Gets the value of the aliases. * * @return * the value of the aliases */ public List<String> getAliasesValue() { List<String> aliasesValue = new ArrayList<String>(); for ( Alias alias : aliases ) { aliasesValue.add( alias.toString() ); } return aliasesValue; } /** * Gets the value of the description. * * @return * the value of the description */ public String getDescriptionValue() { return descriptionText.getText(); } /** * Sets the selected schema. * * @param schema * the selected schema */ public void setSelectedSchema( Schema schema ) { selectedSchema = 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/widget/DifferencesWidgetSchemaLabelProvider.java
plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/widget/DifferencesWidgetSchemaLabelProvider.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.widget; 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.difference.AttributeTypeDifference; import org.apache.directory.studio.schemaeditor.model.difference.ObjectClassDifference; import org.apache.directory.studio.schemaeditor.model.difference.SchemaDifference; 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 SchemaView. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class DifferencesWidgetSchemaLabelProvider extends LabelProvider { /** The preferences store */ private IPreferenceStore store; /** * Creates a new instance of DifferencesWidgetSchemaLabelProvider. */ public DifferencesWidgetSchemaLabelProvider() { store = Activator.getDefault().getPreferenceStore(); } /** * {@inheritDoc} */ public String getText( Object element ) { String label = ""; //$NON-NLS-1$ 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 ); if ( element instanceof SchemaDifference ) { SchemaDifference sd = ( SchemaDifference ) element; switch ( sd.getType() ) { case ADDED: return ( ( Schema ) sd.getDestination() ).getSchemaName(); case MODIFIED: return ( ( Schema ) sd.getDestination() ).getSchemaName(); case REMOVED: return ( ( Schema ) sd.getSource() ).getSchemaName(); case IDENTICAL: return ( ( Schema ) sd.getDestination() ).getSchemaName(); } } else if ( element instanceof AttributeTypeDifference ) { AttributeTypeDifference atd = ( AttributeTypeDifference ) element; AttributeType at = null; switch ( atd.getType() ) { case ADDED: at = ( ( AttributeType ) atd.getDestination() ); break; case MODIFIED: at = ( ( AttributeType ) atd.getDestination() ); break; case REMOVED: at = ( ( AttributeType ) atd.getSource() ); break; case IDENTICAL: at = ( ( AttributeType ) atd.getDestination() ); break; } // 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( "DifferencesWidgetSchemaLabelProvider.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( "DifferencesWidgetSchemaLabelProvider.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( "DifferencesWidgetSchemaLabelProvider.None" ); //$NON-NLS-1$ } } // Abbreviate if ( abbreviate && ( abbreviateMaxLength < label.length() ) ) { label = label.substring( 0, abbreviateMaxLength ) + "..."; //$NON-NLS-1$ } } else if ( element instanceof ObjectClassDifference ) { ObjectClassDifference ocd = ( ObjectClassDifference ) element; ObjectClass oc = null; switch ( ocd.getType() ) { case ADDED: oc = ( ( ObjectClass ) ocd.getDestination() ); break; case MODIFIED: oc = ( ( ObjectClass ) ocd.getDestination() ); break; case REMOVED: oc = ( ( ObjectClass ) ocd.getSource() ); break; case IDENTICAL: oc = ( ( ObjectClass ) ocd.getDestination() ); break; } // 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( "DifferencesWidgetSchemaLabelProvider.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( "DifferencesWidgetSchemaLabelProvider.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( "DifferencesWidgetSchemaLabelProvider.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; return folder.getName() + " (" + folder.getChildren().size() + ")"; //$NON-NLS-1$ //$NON-NLS-2$ } // Secondary Label if ( secondaryLabelDisplay ) { String secondaryLabel = ""; //$NON-NLS-1$ if ( element instanceof AttributeTypeDifference ) { AttributeTypeDifference atd = ( AttributeTypeDifference ) element; AttributeType at = null; switch ( atd.getType() ) { case ADDED: at = ( ( AttributeType ) atd.getDestination() ); break; case MODIFIED: at = ( ( AttributeType ) atd.getDestination() ); break; case REMOVED: at = ( ( AttributeType ) atd.getSource() ); break; case IDENTICAL: at = ( ( AttributeType ) atd.getDestination() ); break; } 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( "DifferencesWidgetSchemaLabelProvider.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( "DifferencesWidgetSchemaLabelProvider.None" ); //$NON-NLS-1$ } } else if ( secondaryLabelValue == PluginConstants.PREFS_SCHEMA_VIEW_LABEL_OID ) { secondaryLabel = at.getOid(); } } else if ( element instanceof ObjectClassDifference ) { ObjectClassDifference ocd = ( ObjectClassDifference ) element; ObjectClass oc = null; switch ( ocd.getType() ) { case ADDED: oc = ( ( ObjectClass ) ocd.getDestination() ); break; case MODIFIED: oc = ( ( ObjectClass ) ocd.getDestination() ); break; case REMOVED: oc = ( ( ObjectClass ) ocd.getSource() ); break; case IDENTICAL: oc = ( ( ObjectClass ) ocd.getDestination() ); break; } 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( "DifferencesWidgetSchemaLabelProvider.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( "DifferencesWidgetSchemaLabelProvider.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$ } return label; } /** * {@inheritDoc} */ public Image getImage( Object element ) { if ( element instanceof SchemaDifference ) { SchemaDifference sd = ( SchemaDifference ) element; switch ( sd.getType() ) { case ADDED: return Activator.getDefault().getImage( PluginConstants.IMG_DIFFERENCE_SCHEMA_ADD ); case MODIFIED: return Activator.getDefault().getImage( PluginConstants.IMG_DIFFERENCE_SCHEMA_MODIFY ); case REMOVED: return Activator.getDefault().getImage( PluginConstants.IMG_DIFFERENCE_SCHEMA_REMOVE ); case IDENTICAL: return Activator.getDefault().getImage( PluginConstants.IMG_SCHEMA ); } } else if ( element instanceof AttributeTypeDifference ) { AttributeTypeDifference atd = ( AttributeTypeDifference ) element; switch ( atd.getType() ) { case ADDED: return Activator.getDefault().getImage( PluginConstants.IMG_DIFFERENCE_ATTRIBUTE_TYPE_ADD ); case MODIFIED: return Activator.getDefault().getImage( PluginConstants.IMG_DIFFERENCE_ATTRIBUTE_TYPE_MODIFY ); case REMOVED: return Activator.getDefault().getImage( PluginConstants.IMG_DIFFERENCE_ATTRIBUTE_TYPE_REMOVE ); case IDENTICAL: return Activator.getDefault().getImage( PluginConstants.IMG_ATTRIBUTE_TYPE ); } } else if ( element instanceof ObjectClassDifference ) { ObjectClassDifference ocd = ( ObjectClassDifference ) element; switch ( ocd.getType() ) { case ADDED: return Activator.getDefault().getImage( PluginConstants.IMG_DIFFERENCE_OBJECT_CLASS_ADD ); case MODIFIED: return Activator.getDefault().getImage( PluginConstants.IMG_DIFFERENCE_OBJECT_CLASS_MODIFY ); case REMOVED: return Activator.getDefault().getImage( PluginConstants.IMG_DIFFERENCE_OBJECT_CLASS_REMOVE ); case IDENTICAL: 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/widget/SchemaSourceViewer.java
plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/widget/SchemaSourceViewer.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.widget; import org.eclipse.jface.text.source.IOverviewRuler; import org.eclipse.jface.text.source.IVerticalRuler; import org.eclipse.jface.text.source.SourceViewer; import org.eclipse.swt.widgets.Composite; /** * Implementation of a SourceViewer for displaying Schema files source code. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class SchemaSourceViewer extends SourceViewer { /** * Creates a new instance of SchemaSourceViewer. * * @param parent * the parent of the viewer's control * @param verticalRuler * the vertical ruler used by this source viewer * @param overviewRuler * the overview ruler * @param showAnnotationsOverview * true if the overview ruler should be visible, false otherwise * @param styles * the SWT style bits */ public SchemaSourceViewer( Composite parent, IVerticalRuler verticalRuler, IOverviewRuler overviewRuler, boolean showAnnotationsOverview, int styles ) { super( parent, verticalRuler, overviewRuler, showAnnotationsOverview, styles ); this.configure( new SchemaSourceViewerConfiguration() ); } /** * Creates a new instance of SchemaSourceViewer. * * @param parent * the parent of the viewer's control * @param ruler * the vertical ruler used by this source viewer * @param styles * the SWT style bits */ public SchemaSourceViewer( Composite parent, IVerticalRuler ruler, int styles ) { super( parent, ruler, styles ); this.configure( new SchemaSourceViewerConfiguration() ); } }
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/widget/TypeSorter.java
plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/widget/TypeSorter.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.widget; import java.util.Comparator; import org.apache.directory.studio.schemaeditor.model.difference.AliasDifference; import org.apache.directory.studio.schemaeditor.model.difference.ClassTypeDifference; import org.apache.directory.studio.schemaeditor.model.difference.CollectiveDifference; import org.apache.directory.studio.schemaeditor.model.difference.DescriptionDifference; import org.apache.directory.studio.schemaeditor.model.difference.EqualityDifference; import org.apache.directory.studio.schemaeditor.model.difference.MandatoryATDifference; import org.apache.directory.studio.schemaeditor.model.difference.NoUserModificationDifference; import org.apache.directory.studio.schemaeditor.model.difference.ObsoleteDifference; import org.apache.directory.studio.schemaeditor.model.difference.OptionalATDifference; import org.apache.directory.studio.schemaeditor.model.difference.OrderingDifference; import org.apache.directory.studio.schemaeditor.model.difference.PropertyDifference; import org.apache.directory.studio.schemaeditor.model.difference.SingleValueDifference; import org.apache.directory.studio.schemaeditor.model.difference.SubstringDifference; import org.apache.directory.studio.schemaeditor.model.difference.SuperiorATDifference; import org.apache.directory.studio.schemaeditor.model.difference.SuperiorOCDifference; import org.apache.directory.studio.schemaeditor.model.difference.SyntaxDifference; import org.apache.directory.studio.schemaeditor.model.difference.SyntaxLengthDifference; import org.apache.directory.studio.schemaeditor.model.difference.UsageDifference; /** * This class is used to compare, group and sort Differences by 'Type' * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class TypeSorter implements Comparator<PropertyDifference> { /** * {@inheritDoc} */ public int compare( PropertyDifference diff1, PropertyDifference diff2 ) { return getWeight( diff1 ) - getWeight( diff2 ); } /** * Gets the weight of the given difference * * @param diff * the difference * @return * the weight of the difference */ private int getWeight( PropertyDifference diff ) { if ( diff instanceof AliasDifference ) { switch ( diff.getType() ) { case ADDED: return 1; case REMOVED: return 25; default: break; } } else if ( diff instanceof ClassTypeDifference ) { switch ( diff.getType() ) { case MODIFIED: return 17; default: break; } } else if ( diff instanceof CollectiveDifference ) { switch ( diff.getType() ) { case MODIFIED: return 20; default: break; } } else if ( diff instanceof DescriptionDifference ) { switch ( diff.getType() ) { case ADDED: return 2; case MODIFIED: return 12; case REMOVED: return 26; default: break; } } else if ( diff instanceof EqualityDifference ) { switch ( diff.getType() ) { case ADDED: return 7; case MODIFIED: return 22; case REMOVED: return 31; default: break; } } else if ( diff instanceof MandatoryATDifference ) { switch ( diff.getType() ) { case ADDED: return 10; case REMOVED: return 34; default: break; } } else if ( diff instanceof NoUserModificationDifference ) { switch ( diff.getType() ) { case MODIFIED: return 21; default: break; } } else if ( diff instanceof ObsoleteDifference ) { switch ( diff.getType() ) { case MODIFIED: return 18; default: break; } } else if ( diff instanceof OptionalATDifference ) { switch ( diff.getType() ) { case ADDED: return 11; case REMOVED: return 35; default: break; } } else if ( diff instanceof OrderingDifference ) { switch ( diff.getType() ) { case ADDED: return 8; case MODIFIED: return 23; case REMOVED: return 32; default: break; } } else if ( diff instanceof SingleValueDifference ) { switch ( diff.getType() ) { case MODIFIED: return 19; default: break; } } else if ( diff instanceof SubstringDifference ) { switch ( diff.getType() ) { case ADDED: return 9; case MODIFIED: return 24; case REMOVED: return 33; default: break; } } else if ( diff instanceof SuperiorATDifference ) { switch ( diff.getType() ) { case ADDED: return 3; case MODIFIED: return 13; case REMOVED: return 27; default: break; } } else if ( diff instanceof SuperiorOCDifference ) { switch ( diff.getType() ) { case ADDED: return 4; case REMOVED: return 28; default: break; } } else if ( diff instanceof SyntaxDifference ) { switch ( diff.getType() ) { case ADDED: return 5; case MODIFIED: return 15; case REMOVED: return 29; default: break; } } else if ( diff instanceof SyntaxLengthDifference ) { switch ( diff.getType() ) { case ADDED: return 6; case MODIFIED: return 16; case REMOVED: return 30; default: break; } } else if ( diff instanceof UsageDifference ) { switch ( diff.getType() ) { case MODIFIED: return 14; default: break; } } 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/widget/FirstNameSorter.java
plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/widget/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.widget; import java.util.Comparator; import java.util.List; import org.apache.directory.api.ldap.model.schema.SchemaObject; import org.apache.directory.studio.schemaeditor.model.difference.AttributeTypeDifference; import org.apache.directory.studio.schemaeditor.model.difference.ObjectClassDifference; /** * This class is used to compare and sort ascending two TreeNode. */ public class FirstNameSorter implements Comparator<Object> { /** * {@inheritDoc} */ public int compare( Object o1, Object o2 ) { List<String> o1Names = null; List<String> o2Names = null; if ( ( o1 instanceof AttributeTypeDifference ) && ( o2 instanceof AttributeTypeDifference ) ) { AttributeTypeDifference atd1 = ( AttributeTypeDifference ) o1; AttributeTypeDifference atd2 = ( AttributeTypeDifference ) o2; switch ( atd1.getType() ) { case ADDED: o1Names = ( ( SchemaObject ) atd1.getDestination() ).getNames(); break; case MODIFIED: o1Names = ( ( SchemaObject ) atd1.getDestination() ).getNames(); break; case REMOVED: o1Names = ( ( SchemaObject ) atd1.getSource() ).getNames(); break; case IDENTICAL: o1Names = ( ( SchemaObject ) atd1.getDestination() ).getNames(); break; } switch ( atd2.getType() ) { case ADDED: o2Names = ( ( SchemaObject ) atd2.getDestination() ).getNames(); break; case MODIFIED: o2Names = ( ( SchemaObject ) atd2.getDestination() ).getNames(); break; case REMOVED: o2Names = ( ( SchemaObject ) atd2.getSource() ).getNames(); break; case IDENTICAL: o2Names = ( ( SchemaObject ) atd2.getDestination() ).getNames(); break; } } else if ( ( o1 instanceof ObjectClassDifference ) && ( o2 instanceof ObjectClassDifference ) ) { ObjectClassDifference ocd1 = ( ObjectClassDifference ) o1; ObjectClassDifference ocd2 = ( ObjectClassDifference ) o2; switch ( ocd1.getType() ) { case ADDED: o1Names = ( ( SchemaObject ) ocd1.getDestination() ).getNames(); break; case MODIFIED: o1Names = ( ( SchemaObject ) ocd1.getDestination() ).getNames(); break; case REMOVED: o1Names = ( ( SchemaObject ) ocd1.getSource() ).getNames(); break; case IDENTICAL: o1Names = ( ( SchemaObject ) ocd1.getDestination() ).getNames(); break; } switch ( ocd2.getType() ) { case ADDED: o2Names = ( ( SchemaObject ) ocd2.getDestination() ).getNames(); break; case MODIFIED: o2Names = ( ( SchemaObject ) ocd2.getDestination() ).getNames(); break; case REMOVED: o2Names = ( ( SchemaObject ) ocd2.getSource() ).getNames(); break; case IDENTICAL: o2Names = ( ( SchemaObject ) ocd2.getDestination() ).getNames(); break; } } else if ( ( o1 instanceof AttributeTypeDifference ) && ( o2 instanceof ObjectClassDifference ) ) { AttributeTypeDifference atd = ( AttributeTypeDifference ) o1; ObjectClassDifference ocd = ( ObjectClassDifference ) o2; switch ( atd.getType() ) { case ADDED: o1Names = ( ( SchemaObject ) atd.getDestination() ).getNames(); break; case MODIFIED: o1Names = ( ( SchemaObject ) atd.getDestination() ).getNames(); break; case REMOVED: o1Names = ( ( SchemaObject ) atd.getSource() ).getNames(); break; case IDENTICAL: o1Names = ( ( SchemaObject ) atd.getDestination() ).getNames(); break; } switch ( ocd.getType() ) { case ADDED: o2Names = ( ( SchemaObject ) ocd.getDestination() ).getNames(); break; case MODIFIED: o2Names = ( ( SchemaObject ) ocd.getDestination() ).getNames(); break; case REMOVED: o2Names = ( ( SchemaObject ) ocd.getSource() ).getNames(); break; case IDENTICAL: o2Names = ( ( SchemaObject ) ocd.getDestination() ).getNames(); break; } } else if ( ( o1 instanceof ObjectClassDifference ) && ( o2 instanceof AttributeTypeDifference ) ) { ObjectClassDifference ocd = ( ObjectClassDifference ) o1; AttributeTypeDifference atd = ( AttributeTypeDifference ) o2; switch ( ocd.getType() ) { case ADDED: o1Names = ( ( SchemaObject ) ocd.getDestination() ).getNames(); break; case MODIFIED: o1Names = ( ( SchemaObject ) ocd.getDestination() ).getNames(); break; case REMOVED: o1Names = ( ( SchemaObject ) ocd.getSource() ).getNames(); break; case IDENTICAL: o1Names = ( ( SchemaObject ) ocd.getDestination() ).getNames(); break; } switch ( atd.getType() ) { case ADDED: o2Names = ( ( SchemaObject ) atd.getDestination() ).getNames(); break; case MODIFIED: o2Names = ( ( SchemaObject ) atd.getDestination() ).getNames(); break; case REMOVED: o2Names = ( ( SchemaObject ) atd.getSource() ).getNames(); break; case IDENTICAL: o2Names = ( ( SchemaObject ) atd.getDestination() ).getNames(); break; } } // 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/widget/SchemaDifferenceSorter.java
plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/widget/SchemaDifferenceSorter.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.widget; import java.util.Comparator; import org.apache.directory.studio.schemaeditor.model.Schema; import org.apache.directory.studio.schemaeditor.model.difference.SchemaDifference; /** * This class is used to compare and sort ascending two Schemas */ public class SchemaDifferenceSorter implements Comparator<Object> { /** * {@inheritDoc} */ public int compare( Object o1, Object o2 ) { if ( ( o1 instanceof SchemaDifference ) && ( o2 instanceof SchemaDifference ) ) { SchemaDifference sd1 = ( SchemaDifference ) o1; SchemaDifference sd2 = ( SchemaDifference ) o2; String name1 = ""; //$NON-NLS-1$ String name2 = ""; //$NON-NLS-1$ switch ( sd1.getType() ) { case ADDED: name1 = ( ( Schema ) sd1.getDestination() ).getSchemaName(); break; case MODIFIED: name1 = ( ( Schema ) sd1.getDestination() ).getSchemaName(); break; case REMOVED: name1 = ( ( Schema ) sd1.getSource() ).getSchemaName(); break; case IDENTICAL: name1 = ( ( Schema ) sd1.getDestination() ).getSchemaName(); break; } switch ( sd2.getType() ) { case ADDED: name2 = ( ( Schema ) sd2.getDestination() ).getSchemaName(); break; case MODIFIED: name2 = ( ( Schema ) sd2.getDestination() ).getSchemaName(); break; case REMOVED: name2 = ( ( Schema ) sd2.getSource() ).getSchemaName(); break; case IDENTICAL: name2 = ( ( Schema ) sd2.getDestination() ).getSchemaName(); break; } return name1.compareToIgnoreCase( name2 ); } // 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/widget/SchemaTextAttributeProvider.java
plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/widget/SchemaTextAttributeProvider.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.widget; import java.util.HashMap; import java.util.Map; import org.apache.directory.studio.common.ui.CommonUIConstants; import org.apache.directory.studio.common.ui.CommonUIPlugin; import org.eclipse.jface.text.TextAttribute; import org.eclipse.swt.SWT; /** * This class provides the TextAttributes elements for each kind of attribute. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class SchemaTextAttributeProvider { public static final String DEFAULT_ATTRIBUTE = "__pos_schema_default_attribute"; //$NON-NLS-1$ public static final String STRING_ATTRIBUTE = "__pos_schema_string_attribute"; //$NON-NLS-1$ public static final String KEYWORD_ATTRIBUTE = "__pos_schema_keyword_attribute"; //$NON-NLS-1$ public static final String ATTRIBUTETYPE_ATTRIBUTE = "__pos_schema_attributetype_attribute"; //$NON-NLS-1$ public static final String OBJECTCLASS_ATTRIBUTE = "__pos_schema_objectclass_attribute"; //$NON-NLS-1$ public static final String OID_ATTRIBUTE = "__pos_schema_oid_attribute"; //$NON-NLS-1$ private Map<String, TextAttribute> attributes = new HashMap<String, TextAttribute>(); /** * Creates a new instance of SchemaTextAttributeProvider. * */ public SchemaTextAttributeProvider() { CommonUIPlugin plugin = CommonUIPlugin.getDefault(); attributes.put( DEFAULT_ATTRIBUTE, new TextAttribute( plugin.getColor( CommonUIConstants.DEFAULT_COLOR ) ) ); attributes.put( KEYWORD_ATTRIBUTE, new TextAttribute( plugin.getColor( CommonUIConstants.KEYWORD_2_COLOR ), null, SWT.BOLD ) ); attributes.put( STRING_ATTRIBUTE, new TextAttribute( plugin.getColor( CommonUIConstants.VALUE_COLOR ) ) ); attributes.put( ATTRIBUTETYPE_ATTRIBUTE, new TextAttribute( plugin.getColor( CommonUIConstants.ATTRIBUTE_TYPE_COLOR ), null, SWT.BOLD ) ); attributes.put( OBJECTCLASS_ATTRIBUTE, new TextAttribute( plugin.getColor( CommonUIConstants.OBJECT_CLASS_COLOR ), null, SWT.BOLD ) ); attributes.put( OID_ATTRIBUTE, new TextAttribute( plugin.getColor( CommonUIConstants.OID_COLOR ) ) ); } /** * Gets the correct TextAttribute for the given type * * @param type * the type of element * @return * the correct TextAttribute for the given type */ public TextAttribute getAttribute( String type ) { TextAttribute attr = ( TextAttribute ) attributes.get( type ); if ( attr == null ) { attr = ( TextAttribute ) attributes.get( DEFAULT_ATTRIBUTE ); } return attr; } }
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/widget/DifferencesWidgetPropertiesLabelProvider.java
plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/widget/DifferencesWidgetPropertiesLabelProvider.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.widget; import org.apache.directory.studio.schemaeditor.Activator; import org.apache.directory.studio.schemaeditor.PluginConstants; import org.apache.directory.studio.schemaeditor.model.difference.AliasDifference; import org.apache.directory.studio.schemaeditor.model.difference.ClassTypeDifference; import org.apache.directory.studio.schemaeditor.model.difference.CollectiveDifference; import org.apache.directory.studio.schemaeditor.model.difference.DescriptionDifference; import org.apache.directory.studio.schemaeditor.model.difference.EqualityDifference; import org.apache.directory.studio.schemaeditor.model.difference.MandatoryATDifference; import org.apache.directory.studio.schemaeditor.model.difference.NoUserModificationDifference; import org.apache.directory.studio.schemaeditor.model.difference.ObsoleteDifference; import org.apache.directory.studio.schemaeditor.model.difference.OptionalATDifference; import org.apache.directory.studio.schemaeditor.model.difference.OrderingDifference; import org.apache.directory.studio.schemaeditor.model.difference.PropertyDifference; import org.apache.directory.studio.schemaeditor.model.difference.SingleValueDifference; import org.apache.directory.studio.schemaeditor.model.difference.SubstringDifference; import org.apache.directory.studio.schemaeditor.model.difference.SuperiorATDifference; import org.apache.directory.studio.schemaeditor.model.difference.SuperiorOCDifference; import org.apache.directory.studio.schemaeditor.model.difference.SyntaxDifference; import org.apache.directory.studio.schemaeditor.model.difference.SyntaxLengthDifference; import org.apache.directory.studio.schemaeditor.model.difference.UsageDifference; 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 DifferencesWidget. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class DifferencesWidgetPropertiesLabelProvider extends LabelProvider { /** * {@inheritDoc} */ public Image getImage( Object element ) { if ( element instanceof PropertyDifference ) { PropertyDifference propertyDifference = ( PropertyDifference ) element; switch ( propertyDifference.getType() ) { case ADDED: return Activator.getDefault().getImage( PluginConstants.IMG_DIFFERENCE_PROPERTY_ADD ); case MODIFIED: return Activator.getDefault().getImage( PluginConstants.IMG_DIFFERENCE_PROPERTY_MODIFY ); case REMOVED: return Activator.getDefault().getImage( PluginConstants.IMG_DIFFERENCE_PROPERTY_REMOVE ); default: break; } } // Default return super.getImage( element ); } /** * {@inheritDoc} */ public String getText( Object element ) { if ( element instanceof AliasDifference ) { AliasDifference diff = ( AliasDifference ) element; switch ( diff.getType() ) { case ADDED: return NLS .bind( Messages.getString( "DifferencesWidgetPropertiesLabelProvider.AddAlias" ), new Object[] { diff.getNewValue() } ); //$NON-NLS-1$ case REMOVED: return NLS .bind( Messages.getString( "DifferencesWidgetPropertiesLabelProvider.RemoveAlias" ), new Object[] { diff.getOldValue() } ); //$NON-NLS-1$ default: break; } } else if ( element instanceof ClassTypeDifference ) { ClassTypeDifference diff = ( ClassTypeDifference ) element; switch ( diff.getType() ) { case MODIFIED: return NLS .bind( Messages.getString( "DifferencesWidgetPropertiesLabelProvider.ModifiedClassType" ), new Object[] { diff.getNewValue(), diff.getOldValue() } ); //$NON-NLS-1$ default: break; } } else if ( element instanceof CollectiveDifference ) { CollectiveDifference diff = ( CollectiveDifference ) element; switch ( diff.getType() ) { case MODIFIED: return NLS .bind( Messages.getString( "DifferencesWidgetPropertiesLabelProvider.ModifiedCollective" ), new Object[] { diff.getNewValue(), diff.getOldValue() } ); //$NON-NLS-1$ default: break; } } else if ( element instanceof DescriptionDifference ) { DescriptionDifference diff = ( DescriptionDifference ) element; switch ( diff.getType() ) { case ADDED: return NLS .bind( Messages.getString( "DifferencesWidgetPropertiesLabelProvider.AddedDescription" ), new Object[] { diff.getNewValue() } ); //$NON-NLS-1$ case MODIFIED: return NLS .bind( Messages.getString( "DifferencesWidgetPropertiesLabelProvider.ModifiedDescription" ), new Object[] { diff.getNewValue(), diff.getOldValue() } ); //$NON-NLS-1$ case REMOVED: return NLS .bind( Messages.getString( "DifferencesWidgetPropertiesLabelProvider.RemovedDescription" ), new Object[] { diff.getOldValue() } ); //$NON-NLS-1$ default: break; } } else if ( element instanceof EqualityDifference ) { EqualityDifference diff = ( EqualityDifference ) element; switch ( diff.getType() ) { case ADDED: return NLS .bind( Messages.getString( "DifferencesWidgetPropertiesLabelProvider.AddedMatchingRule" ), new Object[] { diff.getNewValue() } ); //$NON-NLS-1$ case MODIFIED: return NLS .bind( Messages.getString( "DifferencesWidgetPropertiesLabelProvider.ModifiedMatchingRule" ), new Object[] { diff.getNewValue(), diff.getOldValue() } ); //$NON-NLS-1$ case REMOVED: return NLS .bind( Messages.getString( "DifferencesWidgetPropertiesLabelProvider.RemovedMatchingRule" ), new Object[] { diff.getOldValue() } ); //$NON-NLS-1$ default: break; } } else if ( element instanceof MandatoryATDifference ) { MandatoryATDifference diff = ( MandatoryATDifference ) element; switch ( diff.getType() ) { case ADDED: return NLS .bind( Messages.getString( "DifferencesWidgetPropertiesLabelProvider.AddedMandatoryAttributeType" ), new Object[] { diff.getNewValue() } ); //$NON-NLS-1$ case REMOVED: return NLS .bind( Messages .getString( "DifferencesWidgetPropertiesLabelProvider.RemovedMandatoryAttributeType" ), new Object[] { diff.getOldValue() } ); //$NON-NLS-1$ default: break; } } else if ( element instanceof NoUserModificationDifference ) { NoUserModificationDifference diff = ( NoUserModificationDifference ) element; switch ( diff.getType() ) { case MODIFIED: return NLS .bind( Messages .getString( "DifferencesWidgetPropertiesLabelProvider.ModifiedNoUserModificationValue" ), new Object[] { diff.getNewValue(), diff.getOldValue() } ); //$NON-NLS-1$ default: break; } } else if ( element instanceof ObsoleteDifference ) { ObsoleteDifference diff = ( ObsoleteDifference ) element; switch ( diff.getType() ) { case MODIFIED: return NLS .bind( Messages.getString( "DifferencesWidgetPropertiesLabelProvider.ModifiedObsoleteValue" ), new Object[] { diff.getNewValue(), diff.getOldValue() } ); //$NON-NLS-1$ default: break; } } else if ( element instanceof OptionalATDifference ) { OptionalATDifference diff = ( OptionalATDifference ) element; switch ( diff.getType() ) { case ADDED: return NLS .bind( Messages.getString( "DifferencesWidgetPropertiesLabelProvider.AddedOptionalAttributeType" ), new Object[] { diff.getNewValue() } ); //$NON-NLS-1$ case REMOVED: return NLS .bind( Messages .getString( "DifferencesWidgetPropertiesLabelProvider.RemovedOptionalAttributeType" ), new Object[] { diff.getOldValue() } ); //$NON-NLS-1$ default: break; } } else if ( element instanceof OrderingDifference ) { OrderingDifference diff = ( OrderingDifference ) element; switch ( diff.getType() ) { case ADDED: return NLS .bind( Messages.getString( "DifferencesWidgetPropertiesLabelProvider.AddedOrderingMatchingRule" ), new Object[] { diff.getNewValue() } ); //$NON-NLS-1$ case MODIFIED: return NLS .bind( Messages .getString( "DifferencesWidgetPropertiesLabelProvider.ModifiedOrderingMatchingRule" ), new Object[] { diff.getNewValue(), diff.getOldValue() } ); //$NON-NLS-1$ case REMOVED: return NLS .bind( Messages.getString( "DifferencesWidgetPropertiesLabelProvider.RemovedOrderingMatchingRule" ), new Object[] { diff.getOldValue() } ); //$NON-NLS-1$ default: break; } } else if ( element instanceof SingleValueDifference ) { SingleValueDifference diff = ( SingleValueDifference ) element; switch ( diff.getType() ) { case MODIFIED: return NLS .bind( Messages.getString( "DifferencesWidgetPropertiesLabelProvider.ModifiedSingleValueValue" ), new Object[] { diff.getNewValue(), diff.getOldValue() } ); //$NON-NLS-1$ default: break; } } else if ( element instanceof SubstringDifference ) { SubstringDifference diff = ( SubstringDifference ) element; switch ( diff.getType() ) { case ADDED: return NLS .bind( Messages.getString( "DifferencesWidgetPropertiesLabelProvider.AddedSubstringMatchingRule" ), new Object[] { diff.getNewValue() } ); //$NON-NLS-1$ case MODIFIED: return NLS .bind( Messages .getString( "DifferencesWidgetPropertiesLabelProvider.ModifiedSubstringMatchingRule" ), new Object[] { diff.getNewValue(), diff.getOldValue() } ); //$NON-NLS-1$ case REMOVED: return NLS .bind( Messages .getString( "DifferencesWidgetPropertiesLabelProvider.RemovedSubstringMatchingRule" ), new Object[] { diff.getOldValue() } ); //$NON-NLS-1$ default: break; } } else if ( element instanceof SuperiorATDifference ) { SuperiorATDifference diff = ( SuperiorATDifference ) element; switch ( diff.getType() ) { case ADDED: return NLS .bind( Messages.getString( "DifferencesWidgetPropertiesLabelProvider.AddedSuperior" ), new Object[] { diff.getNewValue() } ); //$NON-NLS-1$ case MODIFIED: return NLS .bind( Messages.getString( "DifferencesWidgetPropertiesLabelProvider.ModifiedSuperior" ), new Object[] { diff.getNewValue(), diff.getOldValue() } ); //$NON-NLS-1$ case REMOVED: return NLS .bind( Messages.getString( "DifferencesWidgetPropertiesLabelProvider.RemovedSuperior" ), new Object[] { diff.getOldValue() } ); //$NON-NLS-1$ default: break; } } else if ( element instanceof SuperiorOCDifference ) { SuperiorOCDifference diff = ( SuperiorOCDifference ) element; switch ( diff.getType() ) { case ADDED: return NLS .bind( Messages.getString( "DifferencesWidgetPropertiesLabelProvider.AddedSuperior" ), new Object[] { diff.getNewValue() } ); //$NON-NLS-1$ case REMOVED: return NLS .bind( Messages.getString( "DifferencesWidgetPropertiesLabelProvider.RemovedSuperior" ), new Object[] { diff.getOldValue() } ); //$NON-NLS-1$ default: break; } } else if ( element instanceof SyntaxDifference ) { SyntaxDifference diff = ( SyntaxDifference ) element; switch ( diff.getType() ) { case ADDED: return NLS .bind( Messages.getString( "DifferencesWidgetPropertiesLabelProvider.AddedSyntax" ), new Object[] { diff.getNewValue() } ); //$NON-NLS-1$ case MODIFIED: return NLS .bind( Messages.getString( "DifferencesWidgetPropertiesLabelProvider.ModifiedSyntax" ), new Object[] { diff.getNewValue(), diff.getOldValue() } ); //$NON-NLS-1$ case REMOVED: return NLS .bind( Messages.getString( "DifferencesWidgetPropertiesLabelProvider.RemovedSyntax" ), new Object[] { diff.getOldValue() } ); //$NON-NLS-1$ default: break; } } else if ( element instanceof SyntaxLengthDifference ) { SyntaxLengthDifference diff = ( SyntaxLengthDifference ) element; switch ( diff.getType() ) { case ADDED: return NLS .bind( Messages.getString( "DifferencesWidgetPropertiesLabelProvider.AddedSyntaxLength" ), new Object[] { diff.getNewValue() } ); //$NON-NLS-1$ case MODIFIED: return NLS .bind( Messages.getString( "DifferencesWidgetPropertiesLabelProvider.ModifiedSyntaxLength" ), new Object[] { diff.getNewValue(), diff.getOldValue() } ); //$NON-NLS-1$ case REMOVED: return NLS .bind( Messages.getString( "DifferencesWidgetPropertiesLabelProvider.RemovedSyntaxLength" ), new Object[] { diff.getOldValue() } ); //$NON-NLS-1$ default: break; } } else if ( element instanceof UsageDifference ) { UsageDifference diff = ( UsageDifference ) element; switch ( diff.getType() ) { case MODIFIED: return NLS .bind( Messages.getString( "DifferencesWidgetPropertiesLabelProvider.ModifiedUsage" ), new Object[] { diff.getNewValue(), diff.getOldValue() } ); //$NON-NLS-1$ default: break; } } // 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/widget/Messages.java
plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/widget/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.widget; 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/widget/OidSorter.java
plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/widget/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.widget; import java.util.Comparator; import org.apache.directory.api.ldap.model.schema.SchemaObject; import org.apache.directory.studio.schemaeditor.model.difference.AttributeTypeDifference; import org.apache.directory.studio.schemaeditor.model.difference.ObjectClassDifference; /** * This class is used to compare and sort ascending two DisplayableTreeElement */ public class OidSorter implements Comparator<Object> { /** * {@inheritDoc} */ public int compare( Object o1, Object o2 ) { String oid1 = ""; //$NON-NLS-1$ String oid2 = ""; //$NON-NLS-1$ if ( ( o1 instanceof AttributeTypeDifference ) && ( o2 instanceof AttributeTypeDifference ) ) { AttributeTypeDifference atd1 = ( AttributeTypeDifference ) o1; AttributeTypeDifference atd2 = ( AttributeTypeDifference ) o2; switch ( atd1.getType() ) { case ADDED: oid1 = ( ( SchemaObject ) atd1.getDestination() ).getOid(); break; case MODIFIED: oid1 = ( ( SchemaObject ) atd1.getDestination() ).getOid(); break; case REMOVED: oid1 = ( ( SchemaObject ) atd1.getSource() ).getOid(); break; case IDENTICAL: oid1 = ( ( SchemaObject ) atd1.getDestination() ).getOid(); break; } switch ( atd2.getType() ) { case ADDED: oid2 = ( ( SchemaObject ) atd2.getDestination() ).getOid(); break; case MODIFIED: oid2 = ( ( SchemaObject ) atd2.getDestination() ).getOid(); break; case REMOVED: oid2 = ( ( SchemaObject ) atd2.getSource() ).getOid(); break; case IDENTICAL: oid2 = ( ( SchemaObject ) atd2.getDestination() ).getOid(); break; } } else if ( ( o1 instanceof ObjectClassDifference ) && ( o2 instanceof ObjectClassDifference ) ) { ObjectClassDifference ocd1 = ( ObjectClassDifference ) o1; ObjectClassDifference ocd2 = ( ObjectClassDifference ) o2; switch ( ocd1.getType() ) { case ADDED: oid1 = ( ( SchemaObject ) ocd1.getDestination() ).getOid(); break; case MODIFIED: oid1 = ( ( SchemaObject ) ocd1.getDestination() ).getOid(); break; case REMOVED: oid1 = ( ( SchemaObject ) ocd1.getSource() ).getOid(); break; case IDENTICAL: oid1 = ( ( SchemaObject ) ocd1.getDestination() ).getOid(); break; } switch ( ocd2.getType() ) { case ADDED: oid2 = ( ( SchemaObject ) ocd2.getDestination() ).getOid(); break; case MODIFIED: oid2 = ( ( SchemaObject ) ocd2.getDestination() ).getOid(); break; case REMOVED: oid2 = ( ( SchemaObject ) ocd2.getSource() ).getOid(); break; case IDENTICAL: oid2 = ( ( SchemaObject ) ocd2.getDestination() ).getOid(); break; } } else if ( ( o1 instanceof AttributeTypeDifference ) && ( o2 instanceof ObjectClassDifference ) ) { AttributeTypeDifference atd = ( AttributeTypeDifference ) o1; ObjectClassDifference ocd = ( ObjectClassDifference ) o2; switch ( atd.getType() ) { case ADDED: oid1 = ( ( SchemaObject ) atd.getDestination() ).getOid(); break; case MODIFIED: oid1 = ( ( SchemaObject ) atd.getDestination() ).getOid(); break; case REMOVED: oid1 = ( ( SchemaObject ) atd.getSource() ).getOid(); break; case IDENTICAL: oid1 = ( ( SchemaObject ) atd.getDestination() ).getOid(); break; } switch ( ocd.getType() ) { case ADDED: oid2 = ( ( SchemaObject ) ocd.getDestination() ).getOid(); break; case MODIFIED: oid2 = ( ( SchemaObject ) ocd.getDestination() ).getOid(); break; case REMOVED: oid2 = ( ( SchemaObject ) ocd.getSource() ).getOid(); break; case IDENTICAL: oid2 = ( ( SchemaObject ) ocd.getDestination() ).getOid(); break; } } else if ( ( o1 instanceof ObjectClassDifference ) && ( o2 instanceof AttributeTypeDifference ) ) { ObjectClassDifference ocd = ( ObjectClassDifference ) o1; AttributeTypeDifference atd = ( AttributeTypeDifference ) o2; switch ( ocd.getType() ) { case ADDED: oid1 = ( ( SchemaObject ) ocd.getDestination() ).getOid(); break; case MODIFIED: oid1 = ( ( SchemaObject ) ocd.getDestination() ).getOid(); break; case REMOVED: oid1 = ( ( SchemaObject ) ocd.getSource() ).getOid(); break; case IDENTICAL: oid1 = ( ( SchemaObject ) ocd.getDestination() ).getOid(); break; } switch ( atd.getType() ) { case ADDED: oid2 = ( ( SchemaObject ) atd.getDestination() ).getOid(); break; case MODIFIED: oid2 = ( ( SchemaObject ) atd.getDestination() ).getOid(); break; case REMOVED: oid2 = ( ( SchemaObject ) atd.getSource() ).getOid(); break; case IDENTICAL: oid2 = ( ( SchemaObject ) atd.getDestination() ).getOid(); break; } } return oid1.compareToIgnoreCase( oid2 ); } }
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/widget/SchemaSourceViewerConfiguration.java
plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/widget/SchemaSourceViewerConfiguration.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.widget; import org.apache.directory.studio.schemaeditor.Activator; import org.eclipse.jface.text.IDocument; import org.eclipse.jface.text.presentation.IPresentationReconciler; import org.eclipse.jface.text.presentation.PresentationReconciler; import org.eclipse.jface.text.rules.DefaultDamagerRepairer; import org.eclipse.jface.text.source.ISourceViewer; import org.eclipse.jface.text.source.SourceViewerConfiguration; /** * This class is used to handle the display (syntax highlighting, etc.) of Schema files in the SchemaSourceViewer. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class SchemaSourceViewerConfiguration extends SourceViewerConfiguration { /** * {@inheritDoc} */ public IPresentationReconciler getPresentationReconciler( ISourceViewer sourceViewer ) { PresentationReconciler reconciler = new PresentationReconciler(); reconciler.setDocumentPartitioning( getConfiguredDocumentPartitioning( sourceViewer ) ); // Creating the damager/repairer for code DefaultDamagerRepairer dr = new DefaultDamagerRepairer( Activator.getDefault().getSchemaCodeScanner() ); reconciler.setDamager( dr, IDocument.DEFAULT_CONTENT_TYPE ); reconciler.setRepairer( dr, IDocument.DEFAULT_CONTENT_TYPE ); return reconciler; } }
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/widget/PropertySorter.java
plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/widget/PropertySorter.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.widget; import java.util.Comparator; import org.apache.directory.studio.schemaeditor.model.difference.AliasDifference; import org.apache.directory.studio.schemaeditor.model.difference.ClassTypeDifference; import org.apache.directory.studio.schemaeditor.model.difference.CollectiveDifference; import org.apache.directory.studio.schemaeditor.model.difference.DescriptionDifference; import org.apache.directory.studio.schemaeditor.model.difference.EqualityDifference; import org.apache.directory.studio.schemaeditor.model.difference.MandatoryATDifference; import org.apache.directory.studio.schemaeditor.model.difference.NoUserModificationDifference; import org.apache.directory.studio.schemaeditor.model.difference.ObsoleteDifference; import org.apache.directory.studio.schemaeditor.model.difference.OptionalATDifference; import org.apache.directory.studio.schemaeditor.model.difference.OrderingDifference; import org.apache.directory.studio.schemaeditor.model.difference.PropertyDifference; import org.apache.directory.studio.schemaeditor.model.difference.SingleValueDifference; import org.apache.directory.studio.schemaeditor.model.difference.SubstringDifference; import org.apache.directory.studio.schemaeditor.model.difference.SuperiorATDifference; import org.apache.directory.studio.schemaeditor.model.difference.SuperiorOCDifference; import org.apache.directory.studio.schemaeditor.model.difference.SyntaxDifference; import org.apache.directory.studio.schemaeditor.model.difference.SyntaxLengthDifference; import org.apache.directory.studio.schemaeditor.model.difference.UsageDifference; /** * This class is used to compare, group and sort Differences by 'Property' * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class PropertySorter implements Comparator<PropertyDifference> { /** * {@inheritDoc} */ public int compare( PropertyDifference diff1, PropertyDifference diff2 ) { return getWeight( diff1 ) - getWeight( diff2 ); } /** * Gets the weight of the given difference * * @param diff * the difference * @return * the weight of the difference */ private int getWeight( PropertyDifference diff ) { if ( diff instanceof AliasDifference ) { switch ( diff.getType() ) { case ADDED: return 1; case REMOVED: return 2; default: break; } } else if ( diff instanceof ClassTypeDifference ) { switch ( diff.getType() ) { case MODIFIED: return 18; default: break; } } else if ( diff instanceof CollectiveDifference ) { switch ( diff.getType() ) { case MODIFIED: return 21; default: break; } } else if ( diff instanceof DescriptionDifference ) { switch ( diff.getType() ) { case ADDED: return 3; case MODIFIED: return 4; case REMOVED: return 5; default: break; } } else if ( diff instanceof EqualityDifference ) { switch ( diff.getType() ) { case ADDED: return 23; case MODIFIED: return 24; case REMOVED: return 25; default: break; } } else if ( diff instanceof MandatoryATDifference ) { switch ( diff.getType() ) { case ADDED: return 32; case REMOVED: return 33; default: break; } } else if ( diff instanceof NoUserModificationDifference ) { switch ( diff.getType() ) { case MODIFIED: return 22; default: break; } } else if ( diff instanceof ObsoleteDifference ) { switch ( diff.getType() ) { case MODIFIED: return 19; default: break; } } else if ( diff instanceof OptionalATDifference ) { switch ( diff.getType() ) { case ADDED: return 34; case REMOVED: return 35; default: break; } } else if ( diff instanceof OrderingDifference ) { switch ( diff.getType() ) { case ADDED: return 26; case MODIFIED: return 27; case REMOVED: return 28; default: break; } } else if ( diff instanceof SingleValueDifference ) { switch ( diff.getType() ) { case MODIFIED: return 20; default: break; } } else if ( diff instanceof SubstringDifference ) { switch ( diff.getType() ) { case ADDED: return 29; case MODIFIED: return 30; case REMOVED: return 31; default: break; } } else if ( diff instanceof SuperiorATDifference ) { switch ( diff.getType() ) { case ADDED: return 6; case MODIFIED: return 7; case REMOVED: return 8; default: break; } } else if ( diff instanceof SuperiorOCDifference ) { switch ( diff.getType() ) { case ADDED: return 9; case REMOVED: return 10; default: break; } } else if ( diff instanceof SyntaxDifference ) { switch ( diff.getType() ) { case ADDED: return 12; case MODIFIED: return 13; case REMOVED: return 14; default: break; } } else if ( diff instanceof SyntaxLengthDifference ) { switch ( diff.getType() ) { case ADDED: return 15; case MODIFIED: return 16; case REMOVED: return 17; default: break; } } else if ( diff instanceof UsageDifference ) { switch ( diff.getType() ) { case MODIFIED: return 11; default: break; } } 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/widget/DifferencesWidgetSchemaContentProvider.java
plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/widget/DifferencesWidgetSchemaContentProvider.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.widget; 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.PluginConstants; import org.apache.directory.studio.schemaeditor.model.difference.SchemaDifference; import org.apache.directory.studio.schemaeditor.view.widget.Folder.FolderType; 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 Difference Widget. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class DifferencesWidgetSchemaContentProvider 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 SchemaDifferenceSorter schemaDifferenceSorter; /** * Creates a new instance of DifferencesWidgetSchemaContentProvider. */ public DifferencesWidgetSchemaContentProvider() { store = Activator.getDefault().getPreferenceStore(); firstNameSorter = new FirstNameSorter(); oidSorter = new OidSorter(); schemaDifferenceSorter = new SchemaDifferenceSorter(); } /** * {@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<Object> children = new ArrayList<Object>(); 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 List ) { List<SchemaDifference> schemaDifferences = ( List<SchemaDifference> ) parentElement; children.addAll( schemaDifferences ); Collections.sort( children, schemaDifferenceSorter ); } else if ( parentElement instanceof SchemaDifference ) { SchemaDifference difference = ( SchemaDifference ) parentElement; if ( group == PluginConstants.PREFS_SCHEMA_VIEW_GROUPING_FOLDERS ) { Folder atFolder = new Folder( FolderType.ATTRIBUTE_TYPE ); atFolder.addAllChildren( difference.getAttributeTypesDifferences() ); children.add( atFolder ); Folder ocFolder = new Folder( FolderType.OBJECT_CLASS ); ocFolder.addAllChildren( difference.getObjectClassesDifferences() ); children.add( ocFolder ); } else if ( group == PluginConstants.PREFS_SCHEMA_VIEW_GROUPING_MIXED ) { children.addAll( difference.getAttributeTypesDifferences() ); children.addAll( difference.getObjectClassesDifferences() ); // 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.addAll( ( ( Folder ) 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 ); } } return children.toArray(); } /** * {@inheritDoc} */ public Object getParent( Object element ) { // Default return null; } /** * {@inheritDoc} */ public boolean hasChildren( Object element ) { if ( element instanceof SchemaDifference ) { return true; } else if ( element instanceof Folder ) { return true; } // 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/widget/DifferencesWidgetPropertiesContentProvider.java
plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/widget/DifferencesWidgetPropertiesContentProvider.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.widget; import java.util.Collections; import java.util.List; import org.apache.directory.studio.schemaeditor.Activator; import org.apache.directory.studio.schemaeditor.PluginConstants; import org.apache.directory.studio.schemaeditor.model.difference.PropertyDifference; import org.eclipse.jface.preference.IPreferenceStore; import org.eclipse.jface.viewers.IStructuredContentProvider; import org.eclipse.jface.viewers.Viewer; /** * This class implements the ContentProvider for the DifferencesWidget. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class DifferencesWidgetPropertiesContentProvider implements IStructuredContentProvider { /** The PropertySorter */ private PropertySorter propertySorter; /** The TypeSorter */ private TypeSorter typeSorter; /** The PreferenceStore */ private IPreferenceStore store; /** * Creates a new instance of DifferencesWidgetPropertiesContentProvider. * */ public DifferencesWidgetPropertiesContentProvider() { propertySorter = new PropertySorter(); typeSorter = new TypeSorter(); store = Activator.getDefault().getPreferenceStore(); } /** * {@inheritDoc} */ @SuppressWarnings("unchecked") public Object[] getElements( Object inputElement ) { if ( inputElement instanceof List ) { List<PropertyDifference> differences = ( List<PropertyDifference> ) inputElement; int prefValue = store.getInt( PluginConstants.PREFS_DIFFERENCES_WIDGET_GROUPING ); if ( prefValue == PluginConstants.PREFS_DIFFERENCES_WIDGET_GROUPING_PROPERTY ) { Collections.sort( differences, propertySorter ); } else if ( prefValue == PluginConstants.PREFS_DIFFERENCES_WIDGET_GROUPING_TYPE ) { Collections.sort( differences, typeSorter ); } return differences.toArray(); } // Default return null; } /** * {@inheritDoc} */ public void dispose() { // Nothing to do } /** * {@inheritDoc} */ public void inputChanged( Viewer viewer, Object oldInput, Object newInput ) { // Nothing do to } }
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/widget/CoreSchemasSelectionWidget.java
plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/widget/CoreSchemasSelectionWidget.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.widget; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import org.apache.directory.studio.schemaeditor.Activator; import org.apache.directory.studio.schemaeditor.PluginConstants; import org.eclipse.jface.viewers.ArrayContentProvider; import org.eclipse.jface.viewers.CheckboxTableViewer; import org.eclipse.jface.viewers.LabelProvider; import org.eclipse.swt.SWT; 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.Group; import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Table; /** * This class implements a CoreSchemasSelectionWidget. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class CoreSchemasSelectionWidget { /** * This enum represents the different server types. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public enum ServerTypeEnum { APACHE_DS, OPENLDAP } /** The array containing the 'core' from ApacheDS */ private static final String[] coreSchemasFromApacheDS = new String[] { "adsconfig", "apache", "apachedns", "apachemeta", "autofs", "collective", "corba", "core", "cosine", "dhcp", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$ //$NON-NLS-9$ //$NON-NLS-10$ "inetorgperson", "java", "krb5kdc", "mozilla", "nis", "pwdpolicy", "samba", "system" }; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$ /** The array containing the 'core' from OpenLDAP */ private static final String[] coreSchemasFromOpenLdap = new String[] { "collective", "corba", "core", "cosine", "dyngroup", "duaconf", "inetorgperson", "java", "misc", "nis", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$ //$NON-NLS-9$ //$NON-NLS-10$ "openldap", "ppolicy", "system" }; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ // UI Fields private Button typeApacheDSButton; private Button typeOpenLDAPButton; private CheckboxTableViewer coreSchemasTableViewer; /** * Creates the widget. * * @param parent * the parent Composite * @return * the associated composite */ public Composite createWidget( Composite parent ) { Composite composite = new Composite( parent, SWT.NONE ); composite.setLayout( new GridLayout( 2, false ) ); composite.setLayoutData( new GridData( SWT.FILL, SWT.FILL, true, true ) ); // Server Type Group Group serverTypeGroup = new Group( composite, SWT.NONE ); serverTypeGroup.setText( Messages.getString( "CoreSchemasSelectionWidget.ServerType" ) ); //$NON-NLS-1$ serverTypeGroup.setLayout( new GridLayout( 2, false ) ); serverTypeGroup.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false, 2, 1 ) ); // Type ApacheDS Button typeApacheDSButton = new Button( serverTypeGroup, SWT.RADIO ); typeApacheDSButton.setText( Messages.getString( "CoreSchemasSelectionWidget.ApacheDS" ) ); //$NON-NLS-1$ typeApacheDSButton.addSelectionListener( new SelectionAdapter() { public void widgetSelected( SelectionEvent e ) { resetTableViewerWithCoreSchemasFromApacheDS(); } } ); // Type OpenLDAP Button typeOpenLDAPButton = new Button( serverTypeGroup, SWT.RADIO ); typeOpenLDAPButton.setText( Messages.getString( "CoreSchemasSelectionWidget.OpenLDAP" ) ); //$NON-NLS-1$ typeOpenLDAPButton.addSelectionListener( new SelectionAdapter() { public void widgetSelected( SelectionEvent e ) { resetTableViewerWithCoreSchemasFromOpenLdap(); } } ); // Core Schemas Label Label coreSchemaslabel = new Label( composite, SWT.NONE ); coreSchemaslabel.setText( Messages.getString( "CoreSchemasSelectionWidget.ChooseCoreSchemas" ) ); //$NON-NLS-1$ coreSchemaslabel.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false, 2, 1 ) ); // Core Schemas TableViewer coreSchemasTableViewer = new CheckboxTableViewer( new Table( composite, SWT.BORDER | SWT.CHECK | SWT.FULL_SELECTION ) ); GridData gridData = new GridData( SWT.FILL, SWT.FILL, true, true, 1, 2 ); gridData.heightHint = 127; coreSchemasTableViewer.getTable().setLayoutData( gridData ); coreSchemasTableViewer.setContentProvider( new ArrayContentProvider() ); coreSchemasTableViewer.setLabelProvider( new LabelProvider() { public Image getImage( Object element ) { return Activator.getDefault().getImage( PluginConstants.IMG_SCHEMA ); } } ); Button coreSchemasTableSelectAllButton = new Button( composite, SWT.PUSH ); coreSchemasTableSelectAllButton.setText( Messages.getString( "CoreSchemasSelectionWidget.SelectAll" ) ); //$NON-NLS-1$ coreSchemasTableSelectAllButton.setLayoutData( new GridData( SWT.FILL, SWT.BEGINNING, false, false ) ); coreSchemasTableSelectAllButton.addSelectionListener( new SelectionAdapter() { public void widgetSelected( SelectionEvent e ) { coreSchemasTableViewer.setAllChecked( true ); } } ); Button coreSchemasTableDeselectAllButton = new Button( composite, SWT.PUSH ); coreSchemasTableDeselectAllButton.setText( Messages.getString( "CoreSchemasSelectionWidget.DeselectAll" ) ); //$NON-NLS-1$ coreSchemasTableDeselectAllButton.setLayoutData( new GridData( SWT.FILL, SWT.BEGINNING, false, false ) ); coreSchemasTableDeselectAllButton.addSelectionListener( new SelectionAdapter() { public void widgetSelected( SelectionEvent e ) { coreSchemasTableViewer.setAllChecked( false ); } } ); return composite; } /** * Gets the checked 'core' schemas. * * @return * the checked 'core' schemas. */ public String[] getCheckedCoreSchemas() { return Arrays.asList( coreSchemasTableViewer.getCheckedElements() ).toArray( new String[0] ); } /** * Gets the grayed 'core' schemas. * * @return * the grayed 'core' schemas */ public String[] getGrayedCoreSchemas() { return Arrays.asList( coreSchemasTableViewer.getGrayedElements() ).toArray( new String[0] ); } /** * Gets the selected 'core' schemas. * * @return * the selected 'core' schemas */ public String[] getSelectedCoreSchemas() { List<String> selectedSchemas = new ArrayList<String>(); selectedSchemas.addAll( Arrays.asList( getCheckedCoreSchemas() ) ); selectedSchemas.removeAll( Arrays.asList( getGrayedCoreSchemas() ) ); return selectedSchemas.toArray( new String[0] ); } /** * Gets the Server Type * * @return * the Server Type */ public ServerTypeEnum getServerType() { if ( typeApacheDSButton.getSelection() ) { return ServerTypeEnum.APACHE_DS; } else if ( typeOpenLDAPButton.getSelection() ) { return ServerTypeEnum.OPENLDAP; } else { // Default return null; } } /** * Initializes the widget. * * @param selectedButton * the selected button: * <ul> * <li>{@link ServerTypeEnum}.APACHE_DS for the "ApacheDS" button</li> * <li>{@link ServerTypeEnum}.OPENLDAP for the "OpenLDAP" button</li> * </ul> */ public void init( ServerTypeEnum selectedButton ) { // Setting the selected button if ( selectedButton != null ) { switch ( selectedButton ) { case APACHE_DS: typeApacheDSButton.setSelection( true ); resetTableViewerWithCoreSchemasFromApacheDS(); break; case OPENLDAP: typeOpenLDAPButton.setSelection( true ); resetTableViewerWithCoreSchemasFromOpenLdap(); break; } } } /** * Re-initializes the Table Viewer with the 'core' schemas from ApacheDS. */ private void resetTableViewerWithCoreSchemasFromApacheDS() { coreSchemasTableViewer.setAllChecked( false ); coreSchemasTableViewer.setInput( coreSchemasFromApacheDS ); } /** * Re-initializes the Table Viewer with the 'core' schemas from OpenLDAP. */ private void resetTableViewerWithCoreSchemasFromOpenLdap() { coreSchemasTableViewer.setAllChecked( false ); coreSchemasTableViewer.setInput( coreSchemasFromOpenLdap ); } /** * Sets the checked 'core' schemas. * * @param checkedCoreSchemas */ public void setCheckedCoreSchemas( String[] checkedCoreSchemas ) { coreSchemasTableViewer.setCheckedElements( checkedCoreSchemas ); } /** * Sets the grayed 'core' schemas. * * @param grayedCoreSchemas */ public void setGrayedCoreSchemas( String[] grayedCoreSchemas ) { coreSchemasTableViewer.setGrayedElements( grayedCoreSchemas ); } }
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/widget/DifferencesWidget.java
plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/widget/DifferencesWidget.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.widget; import java.util.ArrayList; import java.util.List; import org.apache.directory.studio.schemaeditor.Activator; import org.apache.directory.studio.schemaeditor.PluginConstants; import org.apache.directory.studio.schemaeditor.controller.actions.OpenSchemaViewPreferenceAction; import org.apache.directory.studio.schemaeditor.controller.actions.OpenSchemaViewSortingDialogAction; import org.apache.directory.studio.schemaeditor.model.difference.AttributeTypeDifference; import org.apache.directory.studio.schemaeditor.model.difference.DifferenceType; import org.apache.directory.studio.schemaeditor.model.difference.ObjectClassDifference; import org.apache.directory.studio.schemaeditor.model.difference.SchemaDifference; import org.eclipse.jface.preference.IPreferenceStore; import org.eclipse.jface.util.IPropertyChangeListener; import org.eclipse.jface.util.PropertyChangeEvent; import org.eclipse.jface.viewers.DoubleClickEvent; import org.eclipse.jface.viewers.IDoubleClickListener; 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.jface.viewers.TreeViewer; import org.eclipse.swt.SWT; 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.Composite; import org.eclipse.swt.widgets.Menu; import org.eclipse.swt.widgets.MenuItem; import org.eclipse.swt.widgets.ToolBar; import org.eclipse.swt.widgets.ToolItem; import org.eclipse.ui.PlatformUI; /** * This class represents the DifferencesWidget. * <p> * It is used to display a List of Difference given in input. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class DifferencesWidget { /** The PreferenceStore */ private IPreferenceStore store; /** The authorized Preferences keys */ private List<String> authorizedPrefs; /** The preference listener */ private IPropertyChangeListener preferenceListener = new IPropertyChangeListener() { /** * {@inheritDoc} */ public void propertyChange( PropertyChangeEvent event ) { if ( authorizedPrefs.contains( event.getProperty() ) ) { treeViewer.refresh(); } } }; // The MenuItems private TreeViewer treeViewer; private TableViewer tableViewer; private MenuItem groupByType; private MenuItem groupByProperty; /** * Creates a new instance of DifferencesWidget. */ public DifferencesWidget() { store = Activator.getDefault().getPreferenceStore(); } /** * Creates the widget. * * @param parent * the parent Composite */ public void createWidget( Composite parent ) { // Composite Composite composite = new Composite( parent, SWT.NONE ); GridLayout gridLayout = new GridLayout( 2, true ); gridLayout.marginBottom = 0; gridLayout.marginHeight = 0; gridLayout.marginLeft = 0; gridLayout.marginRight = 0; gridLayout.marginTop = 0; gridLayout.marginWidth = 0; composite.setLayout( gridLayout ); composite.setLayoutData( new GridData( SWT.FILL, SWT.FILL, true, true ) ); // Left Composite Composite leftComposite = new Composite( composite, SWT.NONE ); gridLayout = new GridLayout(); gridLayout.marginBottom = 0; gridLayout.marginHeight = 0; gridLayout.marginLeft = 0; gridLayout.marginRight = 0; gridLayout.marginTop = 0; gridLayout.marginWidth = 0; leftComposite.setLayout( gridLayout ); leftComposite.setLayoutData( new GridData( SWT.FILL, SWT.FILL, true, true ) ); // ToolBar final ToolBar leftToolBar = new ToolBar( leftComposite, SWT.HORIZONTAL | SWT.FLAT ); leftToolBar.setLayoutData( new GridData( SWT.RIGHT, SWT.NONE, false, false ) ); // Creating the 'Menu' ToolBar item final ToolItem leftMenuToolItem = new ToolItem( leftToolBar, SWT.PUSH ); leftMenuToolItem.setImage( Activator.getDefault().getImage( PluginConstants.IMG_TOOLBAR_MENU ) ); leftMenuToolItem.setToolTipText( Messages.getString( "DifferencesWidget.MenuToolTip" ) ); //$NON-NLS-1$ // Creating the associated Menu final Menu leftMenu = new Menu( PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), SWT.POP_UP ); // Adding the action to display the Menu when the item is clicked leftMenuToolItem.addSelectionListener( new SelectionAdapter() { public void widgetSelected( SelectionEvent event ) { Rectangle rect = leftMenuToolItem.getBounds(); Point pt = new Point( rect.x, rect.y + rect.height ); pt = leftToolBar.toDisplay( pt ); leftMenu.setLocation( pt.x, pt.y ); leftMenu.setVisible( true ); } } ); // Adding the 'Sorting...' MenuItem MenuItem sortingMenuItem = new MenuItem( leftMenu, SWT.PUSH ); sortingMenuItem.setText( Messages.getString( "DifferencesWidget.Sorting" ) ); //$NON-NLS-1$ sortingMenuItem.setImage( Activator.getDefault().getImage( PluginConstants.IMG_SORTING ) ); sortingMenuItem.addSelectionListener( new SelectionAdapter() { public void widgetSelected( SelectionEvent arg0 ) { new OpenSchemaViewSortingDialogAction().run(); } } ); // Adding the 'Separator' MenuItem new MenuItem( leftMenu, SWT.SEPARATOR ); // Adding the 'Preferences...' MenuItem MenuItem preferencesMenuItem = new MenuItem( leftMenu, SWT.PUSH ); preferencesMenuItem.setText( Messages.getString( "DifferencesWidget.Preferences" ) ); //$NON-NLS-1$ preferencesMenuItem.addSelectionListener( new SelectionAdapter() { public void widgetSelected( SelectionEvent arg0 ) { new OpenSchemaViewPreferenceAction().run(); } } ); // TreeViewer treeViewer = new TreeViewer( leftComposite, SWT.SINGLE | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER ); GridData gridData = new GridData( SWT.FILL, SWT.FILL, true, true ); gridData.heightHint = 250; treeViewer.getTree().setLayoutData( gridData ); treeViewer.setContentProvider( new DifferencesWidgetSchemaContentProvider() ); treeViewer.setLabelProvider( new DifferencesWidgetSchemaLabelProvider() ); treeViewer.addSelectionChangedListener( new ISelectionChangedListener() { public void selectionChanged( SelectionChangedEvent event ) { StructuredSelection selection = ( StructuredSelection ) event.getSelection(); Object element = selection.getFirstElement(); if ( element instanceof AttributeTypeDifference ) { AttributeTypeDifference atd = ( AttributeTypeDifference ) element; if ( atd.getType().equals( DifferenceType.MODIFIED ) ) { tableViewer.setInput( atd.getDifferences() ); return; } } else if ( element instanceof ObjectClassDifference ) { ObjectClassDifference ocd = ( ObjectClassDifference ) element; if ( ocd.getType().equals( DifferenceType.MODIFIED ) ) { tableViewer.setInput( ocd.getDifferences() ); return; } } // Default tableViewer.setInput( null ); } } ); treeViewer.addDoubleClickListener( new IDoubleClickListener() { public void doubleClick( DoubleClickEvent event ) { StructuredSelection selection = ( StructuredSelection ) event.getSelection(); Object element = selection.getFirstElement(); if ( ( element instanceof Folder ) || ( element instanceof SchemaDifference ) ) { treeViewer.setExpandedState( element, !treeViewer.getExpandedState( element ) ); } } } ); // Right Composite Composite rightComposite = new Composite( composite, SWT.NONE ); gridLayout = new GridLayout(); gridLayout.marginBottom = 0; gridLayout.marginHeight = 0; gridLayout.marginLeft = 0; gridLayout.marginRight = 0; gridLayout.marginTop = 0; gridLayout.marginWidth = 0; rightComposite.setLayout( gridLayout ); rightComposite.setLayoutData( new GridData( SWT.FILL, SWT.FILL, true, true ) ); // ToolBar final ToolBar rightToolBar = new ToolBar( rightComposite, SWT.HORIZONTAL | SWT.FLAT ); rightToolBar.setLayoutData( new GridData( SWT.RIGHT, SWT.NONE, false, false ) ); // Creating the 'Menu' ToolBar item final ToolItem rightMenuToolItem = new ToolItem( rightToolBar, SWT.PUSH ); rightMenuToolItem.setImage( Activator.getDefault().getImage( PluginConstants.IMG_TOOLBAR_MENU ) ); rightMenuToolItem.setToolTipText( Messages.getString( "DifferencesWidget.MenuToolTip" ) ); //$NON-NLS-1$ // Creating the associated Menu final Menu rightMenu = new Menu( PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), SWT.POP_UP ); // Adding the action to display the Menu when the item is clicked rightMenuToolItem.addSelectionListener( new SelectionAdapter() { public void widgetSelected( SelectionEvent event ) { Rectangle rect = rightMenuToolItem.getBounds(); Point pt = new Point( rect.x, rect.y + rect.height ); pt = rightToolBar.toDisplay( pt ); rightMenu.setLocation( pt.x, pt.y ); rightMenu.setVisible( true ); } } ); // Adding the 'Group By Property' MenuItem groupByProperty = new MenuItem( rightMenu, SWT.CHECK ); groupByProperty.setText( Messages.getString( "DifferencesWidget.GroupByProperty" ) ); //$NON-NLS-1$ groupByProperty.addSelectionListener( new SelectionAdapter() { public void widgetSelected( SelectionEvent arg0 ) { changeGrouping( PluginConstants.PREFS_DIFFERENCES_WIDGET_GROUPING_PROPERTY ); } } ); // Adding the 'Group By Type' MenuItem groupByType = new MenuItem( rightMenu, SWT.CHECK ); groupByType.setText( Messages.getString( "DifferencesWidget.GroupByType" ) ); //$NON-NLS-1$ groupByType.addSelectionListener( new SelectionAdapter() { public void widgetSelected( SelectionEvent arg0 ) { changeGrouping( PluginConstants.PREFS_DIFFERENCES_WIDGET_GROUPING_TYPE ); } } ); updateMenuItemsCheckStatus(); // TableViewer tableViewer = new TableViewer( rightComposite, SWT.SINGLE | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER ); tableViewer.getTable().setLayoutData( new GridData( SWT.FILL, SWT.FILL, true, true ) ); tableViewer.setContentProvider( new DifferencesWidgetPropertiesContentProvider() ); tableViewer.setLabelProvider( new DifferencesWidgetPropertiesLabelProvider() ); initAuthorizedPrefs(); initPreferencesListener(); } /** * Sets the Input of the DifferencesWidget. * * @param input * the input */ public void setInput( List<SchemaDifference> input ) { treeViewer.setInput( input ); } /** * Changes the Grouping option. * * @param value * the value to store in the PreferenceStore */ private void changeGrouping( int value ) { store.setValue( PluginConstants.PREFS_DIFFERENCES_WIDGET_GROUPING, value ); updateMenuItemsCheckStatus(); tableViewer.refresh(); } /** * Updates the MenuItmes 'check' state according to the value from the * PreferenceStore. */ private void updateMenuItemsCheckStatus() { int prefValue = store.getInt( PluginConstants.PREFS_DIFFERENCES_WIDGET_GROUPING ); if ( prefValue == PluginConstants.PREFS_DIFFERENCES_WIDGET_GROUPING_PROPERTY ) { groupByProperty.setSelection( true ); groupByType.setSelection( false ); } else if ( prefValue == PluginConstants.PREFS_DIFFERENCES_WIDGET_GROUPING_TYPE ) { groupByProperty.setSelection( false ); groupByType.setSelection( true ); } else { groupByProperty.setSelection( false ); groupByType.setSelection( false ); } } /** * Initializes the Authorized Prefs IDs. */ private void initAuthorizedPrefs() { authorizedPrefs = new ArrayList<String>(); authorizedPrefs.add( PluginConstants.PREFS_SCHEMA_VIEW_LABEL ); authorizedPrefs.add( PluginConstants.PREFS_SCHEMA_VIEW_ABBREVIATE ); authorizedPrefs.add( PluginConstants.PREFS_SCHEMA_VIEW_ABBREVIATE_MAX_LENGTH ); authorizedPrefs.add( PluginConstants.PREFS_SCHEMA_VIEW_SECONDARY_LABEL_DISPLAY ); authorizedPrefs.add( PluginConstants.PREFS_SCHEMA_VIEW_SECONDARY_LABEL ); authorizedPrefs.add( PluginConstants.PREFS_SCHEMA_VIEW_SECONDARY_LABEL_ABBREVIATE ); authorizedPrefs.add( PluginConstants.PREFS_SCHEMA_VIEW_SECONDARY_LABEL_ABBREVIATE_MAX_LENGTH ); authorizedPrefs.add( PluginConstants.PREFS_SCHEMA_VIEW_GROUPING ); authorizedPrefs.add( PluginConstants.PREFS_SCHEMA_VIEW_SORTING_BY ); authorizedPrefs.add( PluginConstants.PREFS_SCHEMA_VIEW_SORTING_ORDER ); } /** * Initializes the listener on the preferences store */ private void initPreferencesListener() { store.addPropertyChangeListener( preferenceListener ); } /** * Disposes the SWT resources allocated by this widget. */ public void dispose() { store.removePropertyChangeListener( preferenceListener ); } }
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/widget/Folder.java
plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/widget/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.widget; import java.util.ArrayList; import java.util.Collection; import java.util.List; import org.apache.directory.studio.schemaeditor.model.difference.Difference; import org.apache.directory.studio.schemaeditor.view.wrappers.TreeNode; /** * This used to represent a folder in a TreeViewer. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class Folder { /** The children */ protected List<Difference> children; /** * 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 ) { 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; default: break; } } /** * 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; } public boolean hasChildren() { if ( children == null ) { return false; } return !children.isEmpty(); } public List<Difference> getChildren() { if ( children == null ) { children = new ArrayList<Difference>(); } return children; } public void addChild( Difference diff ) { if ( children == null ) { children = new ArrayList<Difference>(); } if ( !children.contains( diff ) ) { children.add( diff ); } } public void removeChild( TreeNode node ) { if ( children != null ) { children.remove( node ); } } public boolean addAllChildren( Collection<? extends Difference> c ) { if ( children == null ) { children = new ArrayList<Difference>(); } return children.addAll( 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/widget/SchemaCodeScanner.java
plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/widget/SchemaCodeScanner.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.widget; import java.util.ArrayList; import java.util.List; import org.eclipse.jface.text.rules.IRule; import org.eclipse.jface.text.rules.IToken; import org.eclipse.jface.text.rules.IWhitespaceDetector; import org.eclipse.jface.text.rules.IWordDetector; import org.eclipse.jface.text.rules.RuleBasedScanner; import org.eclipse.jface.text.rules.SingleLineRule; import org.eclipse.jface.text.rules.Token; import org.eclipse.jface.text.rules.WhitespaceRule; import org.eclipse.jface.text.rules.WordRule; /** * Scanner used to analyse Schema code. Allows syntax coloring. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class SchemaCodeScanner extends RuleBasedScanner { String attributype = "attributetype"; //$NON-NLS-1$ String objectclass = "objectclass"; //$NON-NLS-1$ String[] keywords = new String[] { "NAME", "DESC", "OBSOLETE", "SUP", "EQUALITY", "ORDERING", "MUST", "MAY", "STRUCTURAL", "SUBSTR", "SYNTAX", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$ //$NON-NLS-9$ //$NON-NLS-10$ //$NON-NLS-11$ "SINGLE-VALUE", "COLLECTIVE", "NO-USER-MODIFICATION", "USAGE", "userApplications", "directoryOperation", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ "distributedOperation", "dSAOperation", "ABSTRACT", "STRUCTURAL", "AUXILIARY", "MUST", "MAY" }; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ public SchemaCodeScanner( SchemaTextAttributeProvider provider ) { List<IRule> rules = new ArrayList<IRule>(); IToken keyword = new Token( provider.getAttribute( SchemaTextAttributeProvider.KEYWORD_ATTRIBUTE ) ); IToken string = new Token( provider.getAttribute( SchemaTextAttributeProvider.STRING_ATTRIBUTE ) ); IToken undefined = new Token( provider.getAttribute( SchemaTextAttributeProvider.DEFAULT_ATTRIBUTE ) ); IToken ATToken = new Token( provider.getAttribute( SchemaTextAttributeProvider.ATTRIBUTETYPE_ATTRIBUTE ) ); IToken OCToken = new Token( provider.getAttribute( SchemaTextAttributeProvider.OBJECTCLASS_ATTRIBUTE ) ); IToken oid = new Token( provider.getAttribute( SchemaTextAttributeProvider.OID_ATTRIBUTE ) ); // Rules for Strings rules.add( new SingleLineRule( "\"", "\"", string, '\0', true ) ); //$NON-NLS-1$ //$NON-NLS-2$ rules.add( new SingleLineRule( "'", "'", string, '\0', true ) ); //$NON-NLS-1$ //$NON-NLS-2$ // Generic rule for whitespaces rules.add( new WhitespaceRule( new IWhitespaceDetector() { /** * Indicates if the given character is a whitespace * @param c the character to analyse * @return <code>true</code> if the character is to be considered as a whitespace, <code>false</code> if not. * @see org.eclipse.jface.text.rules.IWhitespaceDetector#isWhitespace(char) */ public boolean isWhitespace( char c ) { return Character.isWhitespace( c ); } } ) ); WordRule wrOID = new WordRule( new SchemaOIDDetector(), oid ); rules.add( wrOID ); // If the word isn't in the List, returns undefined WordRule wr = new WordRule( new SchemaWordDetector(), undefined ); // 'attributetype' rule wr.addWord( attributype, ATToken ); // 'objectclass' rule wr.addWord( objectclass, OCToken ); // Adding Keywords for ( String kw : keywords ) { wr.addWord( kw, keyword ); } rules.add( wr ); IRule[] param = new IRule[rules.size()]; rules.toArray( param ); setRules( param ); } /** * This class implements a word detector for Schema * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ static class SchemaWordDetector implements IWordDetector { /** * {@inheritDoc} */ public boolean isWordPart( char c ) { return ( Character.isLetterOrDigit( c ) || c == '_' || c == '-' || c == '$' || c == '#' || c == '@' || c == '~' || c == '.' || c == '?' ); } /** * {@inheritDoc} */ public boolean isWordStart( char c ) { return ( Character.isLetter( c ) || c == '.' || c == '_' || c == '?' || c == '$' ); } } /** * This class implements an OID detector for Schema * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ static class SchemaOIDDetector implements IWordDetector { /** * {@inheritDoc} */ public boolean isWordPart( char c ) { return ( Character.isDigit( c ) || c == '.' ); } /** * {@inheritDoc} */ public boolean isWordStart( char c ) { return ( Character.isDigit( 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/rcp/src/main/java/org/apache/directory/studio/ApplicationActionBarAdvisor.java
plugins/rcp/src/main/java/org/apache/directory/studio/ApplicationActionBarAdvisor.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; import org.apache.directory.studio.actions.OpenFileAction; import org.apache.directory.studio.actions.ReportABugAction; import org.apache.directory.studio.view.ImageKeys; import org.eclipse.core.runtime.Platform; import org.eclipse.jface.action.GroupMarker; import org.eclipse.jface.action.IContributionItem; import org.eclipse.jface.action.ICoolBarManager; import org.eclipse.jface.action.IMenuManager; import org.eclipse.jface.action.IToolBarManager; import org.eclipse.jface.action.MenuManager; import org.eclipse.jface.action.Separator; import org.eclipse.jface.action.ToolBarContributionItem; import org.eclipse.jface.action.ToolBarManager; import org.eclipse.swt.SWT; import org.eclipse.ui.IWorkbenchActionConstants; import org.eclipse.ui.IWorkbenchWindow; import org.eclipse.ui.actions.ActionFactory; import org.eclipse.ui.actions.ContributionItemFactory; import org.eclipse.ui.actions.NewWizardDropDownAction; import org.eclipse.ui.actions.ActionFactory.IWorkbenchAction; import org.eclipse.ui.application.ActionBarAdvisor; import org.eclipse.ui.application.IActionBarConfigurer; import org.eclipse.ui.plugin.AbstractUIPlugin; /** * An action bar advisor is responsible for creating, adding, and disposing of the * actions added to a workbench window. Each window will be populated with * new actions. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class ApplicationActionBarAdvisor extends ActionBarAdvisor { private static final String OS_MACOSX = "macosx"; //$NON-NLS-1$ private OpenFileAction openFileAction; private IWorkbenchAction closeAction; private IWorkbenchAction closeAllAction; private IWorkbenchAction saveAction; private IWorkbenchAction saveAsAction; private IWorkbenchAction saveAllAction; private IWorkbenchAction printAction; private IWorkbenchAction refreshAction; private IWorkbenchAction renameAction; private IWorkbenchAction moveAction; private IWorkbenchAction exitAction; private IWorkbenchAction aboutAction; private IWorkbenchAction preferencesAction; private IWorkbenchAction helpAction; private IWorkbenchAction dynamicHelpAction; private IWorkbenchAction newAction; private IWorkbenchAction newDropDownAction; private IWorkbenchAction importAction; private IWorkbenchAction exportAction; private IWorkbenchAction propertiesAction; private IWorkbenchAction closePerspectiveAction; private IWorkbenchAction closeAllPerspectivesAction; private IWorkbenchAction undoAction; private IWorkbenchAction redoAction; private IWorkbenchAction cutAction; private IWorkbenchAction copyAction; private IWorkbenchAction pasteAction; private IWorkbenchAction deleteAction; private IWorkbenchAction selectAllAction; private IWorkbenchAction findAction; private IContributionItem perspectivesList; private IContributionItem viewsList; private IContributionItem reopenEditorsList; private ReportABugAction reportABug; private IWorkbenchAction backwardHistoryAction; private IWorkbenchAction forwardHistoryAction; private IWorkbenchAction nextAction; private IWorkbenchAction previousAction; private IWorkbenchAction introAction; /** * Creates a new instance of ApplicationActionBarAdvisor. * * @param configurer * the action bar configurer */ public ApplicationActionBarAdvisor( IActionBarConfigurer configurer ) { super( configurer ); } /** * Creates the actions and registers them. * Registering is needed to ensure that key bindings work. * The corresponding commands keybindings are defined in the plugin.xml file. * Registering also provides automatic disposal of the actions when * the window is closed. */ protected void makeActions( final IWorkbenchWindow window ) { // Creates the actions and registers them. // Registering is needed to ensure that key bindings work. // The corresponding commands keybindings are defined in the plugin.xml file. // Registering also provides automatic disposal of the actions when // the window is closed. newAction = ActionFactory.NEW.create( window ); register( newAction ); newAction.setText( Messages.getString( "ApplicationActionBarAdvisor.new" ) ); //$NON-NLS-1$ newDropDownAction = new NewWizardDropDownAction( window ); openFileAction = new OpenFileAction( window ); register( openFileAction ); closeAction = ActionFactory.CLOSE.create( window ); register( closeAction ); closeAllAction = ActionFactory.CLOSE_ALL.create( window ); register( closeAllAction ); saveAction = ActionFactory.SAVE.create( window ); register( saveAction ); saveAsAction = ActionFactory.SAVE_AS.create( window ); register( saveAsAction ); saveAllAction = ActionFactory.SAVE_ALL.create( window ); register( saveAllAction ); printAction = ActionFactory.PRINT.create( window ); register( printAction ); moveAction = ActionFactory.MOVE.create( window ); register( moveAction ); renameAction = ActionFactory.RENAME.create( window ); register( renameAction ); refreshAction = ActionFactory.REFRESH.create( window ); register( refreshAction ); importAction = ActionFactory.IMPORT.create( window ); register( importAction ); exportAction = ActionFactory.EXPORT.create( window ); register( exportAction ); propertiesAction = ActionFactory.PROPERTIES.create( window ); register( propertiesAction ); exitAction = ActionFactory.QUIT.create( window ); register( exitAction ); undoAction = ActionFactory.UNDO.create( window ); register( undoAction ); redoAction = ActionFactory.REDO.create( window ); register( redoAction ); cutAction = ActionFactory.CUT.create( window ); register( cutAction ); copyAction = ActionFactory.COPY.create( window ); register( copyAction ); pasteAction = ActionFactory.PASTE.create( window ); register( pasteAction ); deleteAction = ActionFactory.DELETE.create( window ); register( deleteAction ); selectAllAction = ActionFactory.SELECT_ALL.create( window ); register( selectAllAction ); findAction = ActionFactory.FIND.create( window ); register( findAction ); closePerspectiveAction = ActionFactory.CLOSE_PERSPECTIVE.create( window ); register( closePerspectiveAction ); closeAllPerspectivesAction = ActionFactory.CLOSE_ALL_PERSPECTIVES.create( window ); register( closeAllPerspectivesAction ); aboutAction = ActionFactory.ABOUT.create( window ); aboutAction.setImageDescriptor( AbstractUIPlugin.imageDescriptorFromPlugin( Application.PLUGIN_ID, ImageKeys.ABOUT ) ); register( aboutAction ); preferencesAction = ActionFactory.PREFERENCES.create( window ); preferencesAction.setImageDescriptor( AbstractUIPlugin.imageDescriptorFromPlugin( Application.PLUGIN_ID, ImageKeys.SHOW_PREFERENCES ) ); register( preferencesAction ); helpAction = ActionFactory.HELP_CONTENTS.create( window ); register( helpAction ); dynamicHelpAction = ActionFactory.DYNAMIC_HELP.create( window ); register( dynamicHelpAction ); viewsList = ContributionItemFactory.VIEWS_SHORTLIST.create( window ); perspectivesList = ContributionItemFactory.PERSPECTIVES_SHORTLIST.create( window ); reopenEditorsList = ContributionItemFactory.REOPEN_EDITORS.create( window ); reportABug = new ReportABugAction( window ); reportABug.setImageDescriptor( AbstractUIPlugin.imageDescriptorFromPlugin( Application.PLUGIN_ID, ImageKeys.REPORT_BUG ) ); register( reportABug ); forwardHistoryAction = ActionFactory.FORWARD_HISTORY.create( window ); register( forwardHistoryAction ); backwardHistoryAction = ActionFactory.BACKWARD_HISTORY.create( window ); register( backwardHistoryAction ); nextAction = ActionFactory.NEXT.create( window ); register( nextAction ); previousAction = ActionFactory.PREVIOUS.create( window ); register( previousAction ); introAction = ActionFactory.INTRO.create( window ); introAction.setImageDescriptor( AbstractUIPlugin.imageDescriptorFromPlugin( Application.PLUGIN_ID, ImageKeys.INTRO ) ); register( introAction ); } /** * Populates the Menu Bar */ protected void fillMenuBar( IMenuManager menuBar ) { // Getting the OS String os = Platform.getOS(); // Creating menus MenuManager fileMenu = new MenuManager( Messages.getString( "ApplicationActionBarAdvisor.file" ), IWorkbenchActionConstants.M_FILE ); //$NON-NLS-1$ MenuManager editMenu = new MenuManager( Messages.getString( "ApplicationActionBarAdvisor.edit" ), IWorkbenchActionConstants.M_EDIT ); //$NON-NLS-1$ MenuManager navigateMenu = new MenuManager( Messages.getString( "ApplicationActionBarAdvisor.navigate" ), IWorkbenchActionConstants.M_NAVIGATE ); //$NON-NLS-1$ MenuManager windowMenu = new MenuManager( Messages.getString( "ApplicationActionBarAdvisor.windows" ), IWorkbenchActionConstants.M_WINDOW ); //$NON-NLS-1$ MenuManager helpMenu = new MenuManager( Messages.getString( "ApplicationActionBarAdvisor.help" ), IWorkbenchActionConstants.M_HELP ); //$NON-NLS-1$ MenuManager hiddenMenu = new MenuManager( "Hidden", "org.apache.directory.studio.rcp.hidden" ); //$NON-NLS-1$ //$NON-NLS-2$ hiddenMenu.setVisible( false ); // Adding menus menuBar.add( fileMenu ); menuBar.add( editMenu ); menuBar.add( navigateMenu ); // Add a group marker indicating where action set menus will appear. menuBar.add( new GroupMarker( IWorkbenchActionConstants.MB_ADDITIONS ) ); menuBar.add( windowMenu ); menuBar.add( helpMenu ); menuBar.add( hiddenMenu ); // Populating File Menu fileMenu.add( newAction ); fileMenu.add( new GroupMarker( IWorkbenchActionConstants.NEW_EXT ) ); fileMenu.add( openFileAction ); fileMenu.add( new GroupMarker( IWorkbenchActionConstants.OPEN_EXT ) ); fileMenu.add( new Separator() ); fileMenu.add( closeAction ); fileMenu.add( closeAllAction ); fileMenu.add( new GroupMarker( IWorkbenchActionConstants.CLOSE_EXT ) ); fileMenu.add( new Separator() ); fileMenu.add( saveAction ); fileMenu.add( saveAsAction ); fileMenu.add( saveAllAction ); fileMenu.add( new GroupMarker( IWorkbenchActionConstants.SAVE_EXT ) ); fileMenu.add( new Separator() ); fileMenu.add( refreshAction ); fileMenu.add( new Separator() ); fileMenu.add( printAction ); fileMenu.add( new GroupMarker( IWorkbenchActionConstants.PRINT_EXT ) ); fileMenu.add( new Separator() ); fileMenu.add( importAction ); fileMenu.add( exportAction ); fileMenu.add( new GroupMarker( IWorkbenchActionConstants.IMPORT_EXT ) ); fileMenu.add( new Separator() ); fileMenu.add( propertiesAction ); fileMenu.add( reopenEditorsList ); fileMenu.add( new GroupMarker( IWorkbenchActionConstants.MRU ) ); if ( ApplicationActionBarAdvisor.OS_MACOSX.equalsIgnoreCase( os ) ) { // We hide the exit (quit) action, it will be added by the "Carbon" plugin hiddenMenu.add( exitAction ); } else { fileMenu.add( new Separator() ); fileMenu.add( exitAction ); } // Populating Edit Menu editMenu.add( undoAction ); editMenu.add( redoAction ); editMenu.add( new Separator() ); editMenu.add( cutAction ); editMenu.add( copyAction ); editMenu.add( pasteAction ); editMenu.add( new Separator() ); editMenu.add( deleteAction ); editMenu.add( selectAllAction ); editMenu.add( new Separator() ); editMenu.add( moveAction ); editMenu.add( renameAction ); editMenu.add( new Separator() ); editMenu.add( findAction ); editMenu.add(new GroupMarker(IWorkbenchActionConstants.FIND_EXT)); // Populating Navigate Menu navigateMenu.add( nextAction ); navigateMenu.add( previousAction ); navigateMenu.add( new Separator( IWorkbenchActionConstants.MB_ADDITIONS ) ); navigateMenu.add( new GroupMarker( IWorkbenchActionConstants.NAV_END ) ); navigateMenu.add( new Separator() ); navigateMenu.add( backwardHistoryAction ); navigateMenu.add( forwardHistoryAction ); // Window MenuManager perspectiveMenu = new MenuManager( Messages .getString( "ApplicationActionBarAdvisor.openPerspective" ), "openPerspective" ); //$NON-NLS-1$ //$NON-NLS-2$ perspectiveMenu.add( perspectivesList ); windowMenu.add( perspectiveMenu ); MenuManager viewMenu = new MenuManager( Messages.getString( "ApplicationActionBarAdvisor.showView" ) ); //$NON-NLS-1$ viewMenu.add( viewsList ); windowMenu.add( viewMenu ); windowMenu.add( new Separator() ); windowMenu.add( closePerspectiveAction ); windowMenu.add( closeAllPerspectivesAction ); if ( ApplicationActionBarAdvisor.OS_MACOSX.equalsIgnoreCase( os ) ) { // We hide the preferences action, it will be added by the "Carbon" plugin hiddenMenu.add( preferencesAction ); } else { windowMenu.add( new Separator() ); windowMenu.add( preferencesAction ); } // Help helpMenu.add( introAction ); helpMenu.add( new Separator() ); helpMenu.add( helpAction ); helpMenu.add( dynamicHelpAction ); helpMenu.add( new Separator() ); helpMenu.add( reportABug ); helpMenu.add( new Separator( IWorkbenchActionConstants.MB_ADDITIONS ) ); if ( ApplicationActionBarAdvisor.OS_MACOSX.equalsIgnoreCase( os ) ) { // We hide the about action, it will be added by the "Carbon" plugin hiddenMenu.add( aboutAction ); } else { helpMenu.add( new Separator() ); helpMenu.add( aboutAction ); } } /** * Populates the Cool Bar */ protected void fillCoolBar( ICoolBarManager coolBar ) { // add main tool bar IToolBarManager toolbar = new ToolBarManager( SWT.FLAT | SWT.RIGHT ); toolbar.add( newDropDownAction ); toolbar.add( saveAction ); toolbar.add( printAction ); toolbar.add( preferencesAction ); coolBar.add( new ToolBarContributionItem( toolbar, Application.PLUGIN_ID + ".toolbar" ) ); //$NON-NLS-1$ // add marker for additions coolBar.add( new GroupMarker( IWorkbenchActionConstants.MB_ADDITIONS ) ); // add navigation tool bar // some actions are added from org.eclipse.ui.editor to the HISTORY_GROUP IToolBarManager navToolBar = new ToolBarManager( SWT.FLAT | SWT.RIGHT ); navToolBar.add( new Separator( IWorkbenchActionConstants.HISTORY_GROUP ) ); navToolBar.add( backwardHistoryAction ); navToolBar.add( forwardHistoryAction ); coolBar.add( new ToolBarContributionItem( navToolBar, IWorkbenchActionConstants.TOOLBAR_NAVIGATE ) ); } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/rcp/src/main/java/org/apache/directory/studio/ApplicationWorkbenchAdvisor.java
plugins/rcp/src/main/java/org/apache/directory/studio/ApplicationWorkbenchAdvisor.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; import org.apache.directory.studio.preferences.ShutdownPreferencesPage; import org.eclipse.core.runtime.preferences.IEclipsePreferences; import org.eclipse.core.runtime.preferences.InstanceScope; import org.eclipse.jface.dialogs.Dialog; import org.eclipse.jface.dialogs.TrayDialog; import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.jface.resource.ImageRegistry; import org.eclipse.jface.resource.JFaceResources; import org.eclipse.ui.ISharedImages; import org.eclipse.ui.PlatformUI; import org.eclipse.ui.application.IWorkbenchConfigurer; import org.eclipse.ui.application.IWorkbenchWindowConfigurer; import org.eclipse.ui.application.WorkbenchAdvisor; import org.eclipse.ui.application.WorkbenchWindowAdvisor; /** * This workbench advisor creates the window advisor, and specifies * the perspective id for the initial window.<br /> * <br /> * - initialize Called first to perform any setup such as parsing the command * line, registering adapters, declaring images, etc... IWorkbenchConfigurer<br /> * - preStartup Called after initialization but before the first window is opened. * May be used to set options affecting which editors and views are initially opened. <br /> * - postStartup Called after all windows have been opened or restored, but before * the event loop starts. It can be used to start automatic processes and to open tips or * other windows.<br /> * - preShutdown Called after the event loop has terminated but before any windows * have been closed. <br /> * - postShutdown Called after all windows are closed during Workbench shutdown. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class ApplicationWorkbenchAdvisor extends WorkbenchAdvisor { /** * Performs arbitrary initialization before the workbench starts running.<br /> * <br /> * This method is called during workbench initialization prior to any windows * being opened. Clients must not call this method directly (although super calls * are okay). The default implementation does nothing. Subclasses may override. * Typical clients will use the configurer passed in to tweak the workbench. If * further tweaking is required in the future, the configurer may be obtained using * getWorkbenchConfigurer */ public void initialize( IWorkbenchConfigurer configurer ) { //enable the save/restore windows size & position feature configurer.setSaveAndRestore( true ); //enable help button in dialogs TrayDialog.setDialogHelpAvailable( true ); ImageRegistry reg = JFaceResources.getImageRegistry(); ImageDescriptor helpImage = PlatformUI.getWorkbench().getSharedImages().getImageDescriptor( ISharedImages.IMG_LCL_LINKTO_HELP ); reg.put( Dialog.DLG_IMG_HELP, helpImage ); } /** * Creates a new workbench window advisor for configuring a new workbench * window via the given workbench window configurer. Clients should override * to provide their own window configurer. This method replaces all the other * window and action bar lifecycle methods on the workbench advisor. */ public WorkbenchWindowAdvisor createWorkbenchWindowAdvisor( IWorkbenchWindowConfigurer configurer ) { return new ApplicationWorkbenchWindowAdvisor( configurer ); } /** * Returns the id of the perspective to use for the initial workbench window, * or null if no initial perspective should be shown in the initial workbench * window.<br /> * <br /> * This method is called during startup when the workbench is creating the first * new window. Subclasses must implement.<br /> * <br /> * If the IWorkbenchPreferenceConstants.DEFAULT_PERSPECTIVE_ID preference is * specified, it supercedes the perspective specified here. */ public String getInitialWindowPerspectiveId() { return "org.apache.directory.studio.ldapbrowser.ui.perspective.BrowserPerspective"; //$NON-NLS-1$ } /** * Performs arbitrary finalization before the workbench is about to shut down.<br /> * <br /> * This method is called immediately prior to workbench shutdown before any * windows have been closed. Clients must not call this method directly (although * super calls are okay). The default implementation returns true. Subclasses may * override. */ public boolean preShutdown() { return ShutdownPreferencesPage.promptOnExit(); } @Override public void postStartup() { super.postStartup(); removeDefaultJvmSetting(); } /** * DIRSTUDIO-1188: When launching ApacheDS the first time the same Studio JVM is used and stored in the preferences * (~/.ApacheDirectoryStudio/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.jdt.launching.prefs). * Afterwards that JVM is always used when starting ApacheDS, even if the Studio JVM changes. As there is no * "Installed JREs" preference page in the Studio RCP application this setting is always removed so the current * Studio JVM is used to start ApacheDS. */ private void removeDefaultJvmSetting() { IEclipsePreferences pref = InstanceScope.INSTANCE.getNode( "org.eclipse.jdt.launching" ); pref.remove( "org.eclipse.jdt.launching.PREF_VM_XML" ); } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/rcp/src/main/java/org/apache/directory/studio/Messages.java
plugins/rcp/src/main/java/org/apache/directory/studio/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; import java.util.MissingResourceException; import java.util.ResourceBundle; /** * This class is used to get Strings to display in the User Interface * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class Messages { private static final String BUNDLE_NAME = "org.apache.directory.studio.messages"; //$NON-NLS-1$ private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle.getBundle( BUNDLE_NAME ); /** * Default constuctor */ private Messages() { } /** * Returns a String associated with the key given in parameter * @param key the key associated to the String * @return the corresponding String */ 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/rcp/src/main/java/org/apache/directory/studio/PluginConstants.java
plugins/rcp/src/main/java/org/apache/directory/studio/PluginConstants.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; /** * This class contains all the Constants used in the Plugin. * Final reference -> class shouldn't be extended * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public final class PluginConstants { /** * Ensures no construction of this class, also ensures there is no need for final keyword above * (Implicit super constructor is not visible for default constructor), * but is still self documenting. */ private PluginConstants() { } /** The Add Extension Action ID */ public static final String ACTION_ADD_EXTENSION_ID = "org.apache.directory.studio.newExtensions"; //$NON-NLS-1$ /** The Manage Configuration Action ID */ public static final String ACTION_MANAGE_CONFIGURATION_ID = "org.apache.directory.studio.manageConfiguration"; //$NON-NLS-1$ /** The Open File Action ID */ public static final String ACTION_OPEN_FILE_ID = "org.apache.directory.studio.openFile"; //$NON-NLS-1$ /** The Report A Bug Action ID */ public static final String ACTION_REPORT_A_BUG_ID = "org.apache.directory.studio.reportABug"; //$NON-NLS-1$ /** The Update ActionID */ public static final String ACTION_UPDATE_ID = "org.apache.directory.studio.newUpdates"; //$NON-NLS-1$ /** The Update ActionID */ public static final String PREFERENCE_EXIT_PROMPT_ON_CLOSE_LAST_WINDOW = "exitPromptOnCloseLastWindow"; //$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/rcp/src/main/java/org/apache/directory/studio/ApplicationWorkbenchWindowAdvisor.java
plugins/rcp/src/main/java/org/apache/directory/studio/ApplicationWorkbenchWindowAdvisor.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; import org.eclipse.core.runtime.IAdaptable; import org.eclipse.core.runtime.IProduct; import org.eclipse.core.runtime.Platform; import org.eclipse.osgi.util.NLS; import org.eclipse.swt.graphics.Point; import org.eclipse.ui.IEditorPart; import org.eclipse.ui.IEditorReference; import org.eclipse.ui.IPageListener; import org.eclipse.ui.IPartListener2; import org.eclipse.ui.IPerspectiveDescriptor; import org.eclipse.ui.IPropertyListener; import org.eclipse.ui.IWorkbenchPage; import org.eclipse.ui.IWorkbenchPartConstants; import org.eclipse.ui.IWorkbenchPartReference; import org.eclipse.ui.IWorkbenchWindow; import org.eclipse.ui.PerspectiveAdapter; import org.eclipse.ui.application.ActionBarAdvisor; import org.eclipse.ui.application.IActionBarConfigurer; import org.eclipse.ui.application.IWorkbenchWindowConfigurer; import org.eclipse.ui.application.WorkbenchWindowAdvisor; /** * The workbench window advisor object is created in response to a workbench window * being created (one per window), and is used to configure the window.<br /> * <br /> * The following advisor methods are called at strategic points in the workbench window's * lifecycle (as with the workbench advisor, all occur within the dynamic scope of the call * to PlatformUI.createAndRunWorkbench):<br /> * <br /> * - preWindowOpen - called as the window is being opened; use to configure aspects of the * window other than actions bars<br /> * - postWindowRestore - called after the window has been recreated from a previously saved * state; use to adjust the restored window<br /> * - postWindowCreate - called after the window has been created, either from an initial * state or from a restored state; used to adjust the window<br /> * - openIntro - called immediately before the window is opened in order to create the * introduction component, if any.<br /> * - postWindowOpen - called after the window has been opened; use to hook window listeners, * etc.<br /> * - preWindowShellClose - called when the window's shell is closed by the user; use to * pre-screen window closings * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class ApplicationWorkbenchWindowAdvisor extends WorkbenchWindowAdvisor { private IEditorPart lastActiveEditor = null; private IPerspectiveDescriptor lastPerspective = null; private IWorkbenchPage lastActivePage; private String lastEditorTitle = ""; //$NON-NLS-1$ private IAdaptable lastInput; private IPropertyListener editorPropertyListener = new IPropertyListener() { public void propertyChanged( Object source, int propId ) { if ( propId == IWorkbenchPartConstants.PROP_TITLE ) { if ( lastActiveEditor != null ) { String newTitle = lastActiveEditor.getTitle(); if ( !lastEditorTitle.equals( newTitle ) ) { recomputeTitle(); } } } } }; /** * Default constructor * @param configurer * an object for configuring the workbench window */ public ApplicationWorkbenchWindowAdvisor( IWorkbenchWindowConfigurer configurer ) { super( configurer ); } /** * Creates a new action bar advisor to configure the action bars of the window via * the given action bar configurer. The default implementation returns a new instance * of ActionBarAdvisor. */ public ActionBarAdvisor createActionBarAdvisor( IActionBarConfigurer configurer ) { return new ApplicationActionBarAdvisor( configurer ); } /** * Performs arbitrary actions before the window is opened.<br /> * <br /> * This method is called before the window's controls have been created. Clients must * not call this method directly (although super calls are okay). The default * implementation does nothing. Subclasses may override. Typical clients will use the * window configurer to tweak the workbench window in an application-specific way; * however, filling the window's menu bar, tool bar, and status line must be done in * ActionBarAdvisor.fillActionBars, which is called immediately after this method is * called. */ public void preWindowOpen() { IWorkbenchWindowConfigurer configurer = getWindowConfigurer(); configurer.setInitialSize( new Point( 950, 708 ) ); configurer.setShowCoolBar( true ); configurer.setShowStatusLine( false ); configurer.setShowPerspectiveBar( true ); configurer.setShowProgressIndicator( true ); configurer.setShowFastViewBars( true ); // hopk up the listeners to update the window title // adapted from org.eclipse.ui.internal.ide.application.IDEWorkbenchWindowAdvisor // http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.ui.ide.application/src/org/eclipse/ui/internal/ide/application/IDEWorkbenchWindowAdvisor.java?view=markup hookTitleUpdateListeners( configurer ); } /** * Hooks up the listeners to update the window title. * * @param configurer */ private void hookTitleUpdateListeners( IWorkbenchWindowConfigurer configurer ) { configurer.getWindow().addPageListener( new IPageListener() { public void pageActivated( IWorkbenchPage page ) { updateTitle( false ); } public void pageClosed( IWorkbenchPage page ) { updateTitle( false ); } public void pageOpened( IWorkbenchPage page ) { // do nothing } } ); configurer.getWindow().addPerspectiveListener( new PerspectiveAdapter() { public void perspectiveActivated( IWorkbenchPage page, IPerspectiveDescriptor perspective ) { updateTitle( false ); } public void perspectiveSavedAs( IWorkbenchPage page, IPerspectiveDescriptor oldPerspective, IPerspectiveDescriptor newPerspective ) { updateTitle( false ); } public void perspectiveDeactivated( IWorkbenchPage page, IPerspectiveDescriptor perspective ) { updateTitle( false ); } } ); configurer.getWindow().getPartService().addPartListener( new IPartListener2() { public void partActivated( IWorkbenchPartReference ref ) { if ( ref instanceof IEditorReference ) { updateTitle( false ); } } public void partBroughtToTop( IWorkbenchPartReference ref ) { if ( ref instanceof IEditorReference ) { updateTitle( false ); } } public void partClosed( IWorkbenchPartReference ref ) { updateTitle( false ); } public void partDeactivated( IWorkbenchPartReference ref ) { // do nothing } public void partOpened( IWorkbenchPartReference ref ) { // do nothing } public void partHidden( IWorkbenchPartReference ref ) { if ( ref.getPart( false ) == lastActiveEditor && lastActiveEditor != null ) { updateTitle( true ); } } public void partVisible( IWorkbenchPartReference ref ) { if ( ref.getPart( false ) == lastActiveEditor && lastActiveEditor != null ) { updateTitle( false ); } } public void partInputChanged( IWorkbenchPartReference ref ) { // do nothing } } ); } /** * Computes the title. * * @return the computed title */ private String computeTitle() { IWorkbenchWindowConfigurer configurer = getWindowConfigurer(); IWorkbenchPage currentPage = configurer.getWindow().getActivePage(); IEditorPart activeEditor = null; if ( currentPage != null ) { activeEditor = lastActiveEditor; } String title = null; IProduct product = Platform.getProduct(); if ( product != null ) { title = product.getName(); } if ( title == null ) { title = ""; //$NON-NLS-1$ } if ( currentPage != null ) { if ( activeEditor != null ) { lastEditorTitle = activeEditor.getTitleToolTip(); title = NLS.bind( "{0} - {1}", lastEditorTitle, title ); //$NON-NLS-1$ } IPerspectiveDescriptor persp = currentPage.getPerspective(); String label = ""; //$NON-NLS-1$ if ( persp != null ) { label = persp.getLabel(); } IAdaptable input = currentPage.getInput(); if ( input != null ) { label = currentPage.getLabel(); } if ( label != null && !label.equals( "" ) ) { //$NON-NLS-1$ title = NLS.bind( "{0} - {1}", label, title ); //$NON-NLS-1$ } } return title; } /** * Recomputes the title. */ private void recomputeTitle() { IWorkbenchWindowConfigurer configurer = getWindowConfigurer(); String oldTitle = configurer.getTitle(); String newTitle = computeTitle(); if ( !newTitle.equals( oldTitle ) ) { configurer.setTitle( newTitle ); } } /** * Updates the window title. Format will be: [pageInput -] * [currentPerspective -] [editorInput -] [workspaceLocation -] productName * @param editorHidden */ private void updateTitle( boolean editorHidden ) { IWorkbenchWindowConfigurer configurer = getWindowConfigurer(); IWorkbenchWindow window = configurer.getWindow(); IEditorPart activeEditor = null; IWorkbenchPage currentPage = window.getActivePage(); IPerspectiveDescriptor persp = null; IAdaptable input = null; if ( currentPage != null ) { activeEditor = currentPage.getActiveEditor(); persp = currentPage.getPerspective(); input = currentPage.getInput(); } if ( editorHidden ) { activeEditor = null; } // Nothing to do if the editor hasn't changed if ( activeEditor == lastActiveEditor && currentPage == lastActivePage && persp == lastPerspective && input == lastInput ) { return; } if ( lastActiveEditor != null ) { lastActiveEditor.removePropertyListener( editorPropertyListener ); } lastActiveEditor = activeEditor; lastActivePage = currentPage; lastPerspective = persp; lastInput = input; if ( activeEditor != null ) { activeEditor.addPropertyListener( editorPropertyListener ); } recomputeTitle(); } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/rcp/src/main/java/org/apache/directory/studio/Activator.java
plugins/rcp/src/main/java/org/apache/directory/studio/Activator.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; import java.io.IOException; import java.util.PropertyResourceBundle; import org.eclipse.core.runtime.FileLocator; import org.eclipse.core.runtime.Path; import org.eclipse.core.runtime.Status; import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.ui.plugin.AbstractUIPlugin; import org.osgi.framework.BundleContext; /** * The main plugin class to be used in the desktop. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class Activator extends AbstractUIPlugin { //The shared instance. private static Activator plugin; /** The plugin properties */ private PropertyResourceBundle properties; /** * The constructor. */ public Activator() { plugin = this; } /** * This method is called upon plug-in activation */ public void start( BundleContext context ) throws Exception { super.start( context ); } /** * This method is called when the plug-in is stopped */ public void stop( BundleContext context ) throws Exception { plugin = null; super.stop( context ); } /** * Returns the shared instance. * * @return the shared instance. */ public static Activator getDefault() { return plugin; } /** * Returns an image descriptor for the image file at the given * plug-in relative path. * * @param path the path * @return the image descriptor */ public static ImageDescriptor getImageDescriptor( String path ) { return AbstractUIPlugin.imageDescriptorFromPlugin( Application.PLUGIN_ID, path ); } /** * Gets the plugin properties. * * @return * the plugin properties */ public PropertyResourceBundle getPluginProperties() { if ( properties == null ) { try { properties = new PropertyResourceBundle( FileLocator.openStream( this.getBundle(), new Path( "plugin.properties" ), false ) ); //$NON-NLS-1$ } catch ( IOException e ) { // We can't use the PLUGIN_ID constant since loading the plugin.properties file has failed, // So we're using a default plugin id. getLog().log( new Status( Status.ERROR, "org.apache.directory.studio.rcp", Status.OK, //$NON-NLS-1$ "Unable to get the plugin properties.", e ) ); //$NON-NLS-1$ } } return properties; } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/rcp/src/main/java/org/apache/directory/studio/Application.java
plugins/rcp/src/main/java/org/apache/directory/studio/Application.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; import org.eclipse.equinox.app.IApplication; import org.eclipse.equinox.app.IApplicationContext; import org.eclipse.swt.widgets.Display; import org.eclipse.ui.IWorkbench; import org.eclipse.ui.PlatformUI; /** * This class controls all aspects of the application's execution * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class Application implements IApplication { /** The plugin ID */ public static final String PLUGIN_ID = "org.apache.directory.studio.rcp"; //$NON-NLS-1$ /** * {@inheritDoc} */ public Object start( IApplicationContext context ) throws Exception { Display display = PlatformUI.createDisplay(); try { int returnCode = PlatformUI.createAndRunWorkbench( display, new ApplicationWorkbenchAdvisor() ); if ( returnCode == PlatformUI.RETURN_RESTART ) { return IApplication.EXIT_RESTART; } else { return IApplication.EXIT_OK; } } finally { display.dispose(); } } /** * {@inheritDoc} */ public void stop() { final IWorkbench workbench = PlatformUI.getWorkbench(); if ( workbench == null ) { return; } final Display display = workbench.getDisplay(); display.syncExec( new Runnable() { public void run() { if ( !display.isDisposed() ) { workbench.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/rcp/src/main/java/org/apache/directory/studio/actions/ReportABugAction.java
plugins/rcp/src/main/java/org/apache/directory/studio/actions/ReportABugAction.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.actions; import java.net.MalformedURLException; import java.net.URL; import org.apache.directory.studio.Messages; import org.apache.directory.studio.PluginConstants; import org.eclipse.jface.action.Action; import org.eclipse.jface.action.IAction; import org.eclipse.jface.viewers.ISelection; import org.eclipse.ui.IWorkbenchWindow; import org.eclipse.ui.IWorkbenchWindowActionDelegate; import org.eclipse.ui.PartInitException; /** * The Action is used to open a browser that displays to page for opening a new Jira * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class ReportABugAction extends Action implements IWorkbenchWindowActionDelegate { /** The workbench window */ private IWorkbenchWindow workbenchWindow; /** * Creates a new instance of ReportABugAction. */ public ReportABugAction() { setId( PluginConstants.ACTION_REPORT_A_BUG_ID ); //$NON-NLS-1$ setText( Messages.getString( "ReportABugAction.Report_a_bug" ) ); //$NON-NLS-1$ setToolTipText( Messages.getString( "ReportABugAction.Open_a_web_browser" ) ); //$NON-NLS-1$ setEnabled( true ); } /** * Creates a new instance of ReportABugAction. * * @param window the workbench window */ public ReportABugAction( IWorkbenchWindow window ) { this(); init( window ); } /** * {@inheritDoc} */ public void dispose() { workbenchWindow = null; } /** * {@inheritDoc} */ public void init( IWorkbenchWindow window ) { workbenchWindow = window; } /** * {@inheritDoc} */ public void run( IAction action ) { run(); } /** * {@inheritDoc} */ public void selectionChanged( IAction action, ISelection selection ) { } /** * {@inheritDoc} */ public void run() { try { workbenchWindow.getWorkbench().getBrowserSupport().getExternalBrowser().openURL( new URL( Messages.getString( "ReportABugAction.JIRA_URL" ) ) ); //$NON-NLS-1$ } catch ( PartInitException e ) { } catch ( MalformedURLException e ) { } } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/rcp/src/main/java/org/apache/directory/studio/actions/OpenFileAction.java
plugins/rcp/src/main/java/org/apache/directory/studio/actions/OpenFileAction.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.actions; import java.text.MessageFormat; import org.apache.directory.studio.Messages; import org.apache.directory.studio.PluginConstants; import org.eclipse.core.filesystem.EFS; import org.eclipse.core.filesystem.IFileInfo; import org.eclipse.core.filesystem.IFileStore; import org.eclipse.core.runtime.Path; import org.eclipse.jface.action.Action; import org.eclipse.jface.action.IAction; import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.jface.viewers.ISelection; import org.eclipse.swt.SWT; import org.eclipse.swt.widgets.FileDialog; import org.eclipse.ui.IWorkbenchPage; import org.eclipse.ui.IWorkbenchWindow; import org.eclipse.ui.IWorkbenchWindowActionDelegate; import org.eclipse.ui.PartInitException; import org.eclipse.ui.ide.IDE; /** * The Action is used to open files from file system. * It creates IPathEditorInput inputs. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class OpenFileAction extends Action implements IWorkbenchWindowActionDelegate { private IWorkbenchWindow window; private String filterPath; /** * Creates a new instance of OpenFileAction. */ public OpenFileAction() { setId( PluginConstants.ACTION_OPEN_FILE_ID ); //$NON-NLS-1$ setText( Messages.getString( "OpenFileAction.Open_File" ) ); //$NON-NLS-1$ setToolTipText( Messages.getString( "OpenFileAction.Open_file_from_filesystem" ) ); //$NON-NLS-1$ setEnabled( true ); } /** * Creates a new instance of OpenFileAction. * * @param window the workbench window */ public OpenFileAction( IWorkbenchWindow window ) { this(); init( window ); } /** * {@inheritDoc} */ public void dispose() { window = null; filterPath = null; } /** * {@inheritDoc} */ public void init( IWorkbenchWindow window ) { this.window = window; filterPath = System.getProperty( "user.home" ); //$NON-NLS-1$ } /** * {@inheritDoc} */ public void run( IAction action ) { run(); } /** * {@inheritDoc} */ public void selectionChanged( IAction action, ISelection selection ) { } /** * {@inheritDoc} */ public void run() { FileDialog dialog = new FileDialog( window.getShell(), SWT.OPEN | SWT.MULTI ); dialog.setText( Messages.getString( "OpenFileAction.Open_File" ) ); //$NON-NLS-1$ dialog.setFilterPath( filterPath ); dialog.open(); String[] names = dialog.getFileNames(); if ( names != null ) { filterPath = dialog.getFilterPath(); int numberOfFilesNotFound = 0; StringBuffer notFound = new StringBuffer(); IWorkbenchPage page = window.getActivePage(); for ( String name : names ) { IFileStore fileStore = EFS.getLocalFileSystem().getStore( new Path( filterPath ) ).getChild( name ); IFileInfo fetchInfo = fileStore.fetchInfo(); if ( !fetchInfo.isDirectory() && fetchInfo.exists() ) { try { IDE.openEditorOnFileStore( page, fileStore ); } catch ( PartInitException e ) { MessageDialog.openError( window.getShell(), Messages.getString( "OpenFileAction.Error" ), e //$NON-NLS-1$ .getMessage() ); } } else { if ( ++numberOfFilesNotFound > 1 ) { notFound.append( '\n' ); } notFound.append( fileStore.getName() ); } } if ( numberOfFilesNotFound > 0 ) { String msg = MessageFormat.format( numberOfFilesNotFound == 1 ? Messages .getString( "OpenFileAction.File_not_found" ) : Messages //$NON-NLS-1$ .getString( "OpenFileAction.Files_not_found" ), new Object[] //$NON-NLS-1$ { notFound.toString() } ); MessageDialog.openError( window.getShell(), Messages.getString( "OpenFileAction.Error" ), msg ); //$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/rcp/src/main/java/org/apache/directory/studio/view/ImageKeys.java
plugins/rcp/src/main/java/org/apache/directory/studio/view/ImageKeys.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.view; /** * This class is used to define path for images * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class ImageKeys { // Images for Actions public static final String ABOUT = "resources/icons/about.png"; //$NON-NLS-1$ public static final String INTRO = "resources/icons/intro.gif"; //$NON-NLS-1$ public static final String MANAGE_CONFIGURATION = "resources/icons/manage-configuration.png"; //$NON-NLS-1$ public static final String REPORT_BUG = "resources/icons/bug-report.png"; //$NON-NLS-1$ public static final String SEARCH_UPDATES = "resources/icons/search-updates.png"; //$NON-NLS-1$ public static final String SHOW_PREFERENCES = "resources/icons/preferences.png"; //$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/rcp/src/main/java/org/apache/directory/studio/preferences/RcpPreferencesInitializer.java
plugins/rcp/src/main/java/org/apache/directory/studio/preferences/RcpPreferencesInitializer.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.preferences; import org.apache.directory.studio.Activator; import org.apache.directory.studio.PluginConstants; import org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer; import org.eclipse.jface.preference.IPreferenceStore; /** * This class is used to set default preference values. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class RcpPreferencesInitializer extends AbstractPreferenceInitializer { /** * {@inheritDoc} */ public void initializeDefaultPreferences() { IPreferenceStore store = Activator.getDefault().getPreferenceStore(); store.setDefault( PluginConstants.PREFERENCE_EXIT_PROMPT_ON_CLOSE_LAST_WINDOW, 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/rcp/src/main/java/org/apache/directory/studio/preferences/ShutdownPreferencesPage.java
plugins/rcp/src/main/java/org/apache/directory/studio/preferences/ShutdownPreferencesPage.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.preferences; import org.apache.directory.studio.Activator; import org.apache.directory.studio.Messages; import org.apache.directory.studio.PluginConstants; import org.eclipse.jface.dialogs.IDialogConstants; import org.eclipse.jface.dialogs.MessageDialogWithToggle; import org.eclipse.jface.preference.IPreferenceStore; import org.eclipse.jface.preference.PreferencePage; 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.Composite; import org.eclipse.swt.widgets.Control; import org.eclipse.ui.IWorkbench; import org.eclipse.ui.IWorkbenchPreferencePage; import org.eclipse.ui.PlatformUI; /** * This class implements the Shutdown Preferences Page. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class ShutdownPreferencesPage extends PreferencePage implements IWorkbenchPreferencePage { // UI fields private Button confirmExitClosingLastWindowCheckbox; /** * Creates a new instance of EntryEditorsPreferencePage. */ public ShutdownPreferencesPage() { super( Messages.getString( "ShutdownPreferencesPage.PageTitle" ) ); //$NON-NLS-1$ super.setPreferenceStore( Activator.getDefault().getPreferenceStore() ); } /** * {@inheritDoc} */ public void init( IWorkbench workbench ) { } /** * {@inheritDoc} */ protected Control createContents( Composite parent ) { Composite composite = new Composite( parent, SWT.NONE ); GridLayout gl = new GridLayout(); gl.marginHeight = gl.marginWidth = 0; composite.setLayout( gl ); composite.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) ); confirmExitClosingLastWindowCheckbox = new Button( composite, SWT.CHECK ); confirmExitClosingLastWindowCheckbox.setText( Messages .getString( "ShutdownPreferencesPage.ConfirmExitClosingLastWindow" ) ); //$NON-NLS-1$ refreshUI(); return composite; } /** * Refreshes the UI. */ private void refreshUI() { confirmExitClosingLastWindowCheckbox.setSelection( getPreferenceStore().getBoolean( PluginConstants.PREFERENCE_EXIT_PROMPT_ON_CLOSE_LAST_WINDOW ) ); } /** * {@inheritDoc} */ public boolean performOk() { getPreferenceStore().setValue( PluginConstants.PREFERENCE_EXIT_PROMPT_ON_CLOSE_LAST_WINDOW, confirmExitClosingLastWindowCheckbox.getSelection() ); return true; } /** * {@inheritDoc} */ protected void performDefaults() { getPreferenceStore().setValue( PluginConstants.PREFERENCE_EXIT_PROMPT_ON_CLOSE_LAST_WINDOW, getPreferenceStore().getDefaultBoolean( PluginConstants.PREFERENCE_EXIT_PROMPT_ON_CLOSE_LAST_WINDOW ) ); super.performDefaults(); } /** * Prompts the user (or not, depending on the preferences) while exiting the application. * * @return <code>true</code> if the application needs to be exited, * <code>false</code> if not. */ public static boolean promptOnExit() { // Checking for multiple workbench windows if ( PlatformUI.getWorkbench().getWorkbenchWindowCount() > 1 ) { return true; } // Getting the preferred exit mode from the preferences IPreferenceStore store = Activator.getDefault().getPreferenceStore(); boolean promptOnExit = store.getBoolean( PluginConstants.PREFERENCE_EXIT_PROMPT_ON_CLOSE_LAST_WINDOW ); if ( promptOnExit ) { MessageDialogWithToggle dialog = MessageDialogWithToggle.openOkCancelConfirm( PlatformUI.getWorkbench() .getActiveWorkbenchWindow().getShell(), Messages.getString( "ShutdownPreferencesPage.PromptOnExitTitle" ), //$NON-NLS-1$ Messages.getString( "ShutdownPreferencesPage.PromptOnExitMessage" ), //$NON-NLS-1$ Messages.getString( "ShutdownPreferencesPage.PromptOnExitToggleMessage" ), false, null, null ); //$NON-NLS-1$ // Checking the dialog's return code if ( dialog.getReturnCode() != IDialogConstants.OK_ID ) { return false; } // Saving the preferred exit mode value to the preferences if ( dialog.getToggleState() ) { store.setValue( PluginConstants.PREFERENCE_EXIT_PROMPT_ON_CLOSE_LAST_WINDOW, false ); Activator.getDefault().savePluginPreferences(); } } return 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/ldapbrowser.common/src/test/java/org/apache/directory/studio/ldapbrowser/common/widgets/entryeditor/EntryEditorWidgetSorterTest.java
plugins/ldapbrowser.common/src/test/java/org/apache/directory/studio/ldapbrowser/common/widgets/entryeditor/EntryEditorWidgetSorterTest.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.ldapbrowser.common.widgets.entryeditor; import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.MatcherAssert.assertThat; import org.apache.directory.studio.ldapbrowser.core.model.IAttribute; import org.apache.directory.studio.ldapbrowser.core.model.impl.Attribute; import org.apache.directory.studio.ldapbrowser.core.model.impl.DummyEntry; import org.apache.directory.studio.ldapbrowser.core.model.impl.Value; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; /** * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class EntryEditorWidgetSorterTest { private EntryEditorWidgetSorter sorter; private Value valueA1; private Value valueA2; private Value valueB; private Value empytValue1; private Value empytValue2; @BeforeEach public void setup() { sorter = new EntryEditorWidgetSorter( null ); IAttribute attribute = new Attribute( new DummyEntry( null, null ), "x" ); valueA1 = new Value( attribute, "a" ); valueA2 = new Value( attribute, "a" ); valueB = new Value( attribute, "b" ); empytValue1 = new Value( attribute, "" ); empytValue2 = new Value( attribute, "" ); } @Test public void testEqual() { int result = sorter.compare( null, valueA1, valueA2 ); assertThat( result, equalTo( 0 ) ); } @Test public void testLeftIsSmaller() { int result = sorter.compare( null, valueA1, valueB ); assertThat( result, equalTo( -1 ) ); } @Test public void testRightIsSmaller() { int result = sorter.compare( null, valueB, valueA2 ); assertThat( result, equalTo( 1 ) ); } @Test public void testLeftIsEmpty() { int result = sorter.compare( null, empytValue1, valueA2 ); assertThat( result, equalTo( -1 ) ); } @Test public void testRightIsEmpty() { int result = sorter.compare( null, valueB, empytValue2 ); assertThat( result, equalTo( 1 ) ); } @Test public void testBothAreEmpty() { int result = sorter.compare( null, empytValue1, empytValue2 ); assertThat( result, equalTo( 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/ldapbrowser.common/src/test/java/org/apache/directory/studio/ldapbrowser/common/widgets/search/ReturningAttributesWidgetTest.java
plugins/ldapbrowser.common/src/test/java/org/apache/directory/studio/ldapbrowser/common/widgets/search/ReturningAttributesWidgetTest.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.ldapbrowser.common.widgets.search; import static org.junit.jupiter.api.Assertions.assertArrayEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNull; import org.junit.jupiter.api.Test; /** * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class ReturningAttributesWidgetTest { @Test public void testStringToArrayNull() { String[] attributes = ReturningAttributesWidget.stringToArray( null ); assertNull( attributes ); } @Test public void testStringToArrayEmpty() { String[] attributes = ReturningAttributesWidget.stringToArray( "" ); assertNotNull( attributes ); assertArrayEquals( new String[0], attributes ); } @Test public void testStringToArrayNoAttrs() { String[] attributes = ReturningAttributesWidget.stringToArray( "1.1" ); assertNotNull( attributes ); assertArrayEquals( new String[] { "1.1" }, attributes ); } @Test public void testStringToArraySingleAttribute() { String[] attributes = ReturningAttributesWidget.stringToArray( "cn" ); assertNotNull( attributes ); assertArrayEquals( new String[] { "cn" }, attributes ); } @Test public void testStringToArrayStingleAttributeWithTrailingWhitespace() { String[] attributes = ReturningAttributesWidget.stringToArray( " cn\t " ); assertNotNull( attributes ); assertArrayEquals( new String[] { "cn" }, attributes ); } @Test public void testStringToArrayStingleAttributeWithTrailingCommas() { String[] attributes = ReturningAttributesWidget.stringToArray( " , ,cn,," ); assertNotNull( attributes ); assertArrayEquals( new String[] { "cn" }, attributes ); } @Test public void testStringToArrayMultipleAttributes() { String[] attributes = ReturningAttributesWidget.stringToArray( "cn, sn uid" ); assertNotNull( attributes ); assertArrayEquals( new String[] { "cn", "sn", "uid" }, attributes ); } @Test public void testStringToArrayMultiplwWithAllUserAndOperationalAttributes() { String[] attributes = ReturningAttributesWidget.stringToArray( "cn, sn uid, * +" ); assertNotNull( attributes ); assertArrayEquals( new String[] { "cn", "sn", "uid", "*", "+" }, attributes ); } @Test public void testStringToArrayMultipleAttributesWithOptions() { String[] attributes = ReturningAttributesWidget.stringToArray( "cn, sn;lang-de;lang-en uid" ); assertNotNull( attributes ); assertArrayEquals( new String[] { "cn", "sn;lang-de;lang-en", "uid" }, attributes ); } @Test public void testStringToArrayMultipleAttributesAsOid() { String[] attributes = ReturningAttributesWidget.stringToArray( "2.5.4.3, 2.5.4.4 0.9.2342.19200300.100.1.1" ); assertNotNull( attributes ); assertArrayEquals( new String[] { "2.5.4.3", "2.5.4.4", "0.9.2342.19200300.100.1.1" }, attributes ); } @Test public void testStringToArrayMultipleAttributesWithUnderscore() { String[] attributes = ReturningAttributesWidget.stringToArray( "cn, s_n u_i_d" ); assertNotNull( attributes ); assertArrayEquals( new String[] { "cn", "s_n", "u_i_d" }, attributes ); } @Test public void testStringToArrayMultipleAttributesWithRangeOption() { String[] attributes = ReturningAttributesWidget.stringToArray( "cn, member;Range=0-* objectClass" ); assertNotNull( attributes ); assertArrayEquals( new String[] { "cn", "member;Range=0-*", "objectClass" }, attributes ); } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/ldapbrowser.common/src/test/java/org/apache/directory/studio/valueeditors/ValueEditorUtilsTest.java
plugins/ldapbrowser.common/src/test/java/org/apache/directory/studio/valueeditors/ValueEditorUtilsTest.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.valueeditors; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; import java.nio.charset.StandardCharsets; import org.junit.jupiter.api.Test; /** * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class ValueEditorUtilsTest { @Test public void testEmptyStringIsEditable() { assertTrue( StringValueEditorUtils.isEditable( "".getBytes() ) ); } @Test public void testAsciiIsEditable() { assertTrue( StringValueEditorUtils.isEditable( "abc\n123".getBytes( StandardCharsets.US_ASCII ) ) ); } @Test public void testUft8IsEditable() { assertTrue( StringValueEditorUtils.isEditable( "a\nb\r\u00e4\t\u5047".getBytes( StandardCharsets.UTF_8 ) ) ); } @Test public void testIso88591IsNotEditable() { assertFalse( StringValueEditorUtils.isEditable( "\u00e4\u00f6\u00fc".getBytes( StandardCharsets.ISO_8859_1 ) ) ); } @Test public void testPngIsNotEditable() { assertFalse( StringValueEditorUtils.isEditable( new byte[] { ( byte ) 0x89, 0x50, 0x4E, 0x47 } ) ); } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/BrowserCommonConstants.java
plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/BrowserCommonConstants.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.ldapbrowser.common; /** * * Final reference -> class shouldn't be extended * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public final class BrowserCommonConstants { /** * Ensures no construction of this class, also ensures there is no need for final keyword above * (Implicit super constructor is not visible for default constructor), * but is still self documenting. */ private BrowserCommonConstants() { } /** The plug-in ID */ public static final String PLUGIN_ID = BrowserCommonConstants.class.getPackage().getName(); public static final String CONTEXT_WINDOWS = BrowserCommonActivator.getDefault().getPluginProperties() .getString( "Ctx_LdapBrowserWindows_id" ); //$NON-NLS-1$ public static final String CONTEXT_DIALOGS = BrowserCommonActivator.getDefault().getPluginProperties() .getString( "Ctx_LdapBrowserDialogs_id" ); //$NON-NLS-1$ public static final String ACTION_ID_EDIT_VALUE = BrowserCommonActivator.getDefault().getPluginProperties() .getString( "Cmd_EditValue_id" ); //$NON-NLS-1$ public static final String ACTION_ID_EDIT_ATTRIBUTE_DESCRIPTION = BrowserCommonActivator.getDefault() .getPluginProperties().getString( "Cmd_EditAttributeDescription_id" ); //$NON-NLS-1$ public static final String ACTION_ID_EDIT_RECORD = BrowserCommonActivator.getDefault().getPluginProperties() .getString( "Cmd_EditRecord_id" ); //$NON-NLS-1$ public static final String DIALOGSETTING_KEY_RECENT_FILE_PATH = "recentFilePath"; //$NON-NLS-1$ public static final String DIALOGSETTING_KEY_FILE_HISTORY = "fileHistory"; //$NON-NLS-1$ public static final String DIALOGSETTING_KEY_RETURNING_ATTRIBUTES_HISTORY = "returningAttributesHistory"; //$NON-NLS-1$ public static final String DIALOGSETTING_KEY_SEARCH_FILTER_HISTORY = "searchFilterHistory"; //$NON-NLS-1$ public static final String DIALOGSETTING_KEY_DN_HISTORY = "dnHistory"; //$NON-NLS-1$ public static final String DIALOGSETTING_KEY_HOST_HISTORY = "hostHistory"; //$NON-NLS-1$ public static final String DIALOGSETTING_KEY_PORT_HISTORY = "portHistory"; //$NON-NLS-1$ public static final String FILTER_TEMPLATE_ID = BrowserCommonActivator.getDefault().getPluginProperties() .getString( "CtxType_LdapFilter_Template_id" ); //$NON-NLS-1$ public static final String EXTENSION_POINT_VALUE_EDITORS = "org.apache.directory.studio.valueeditors"; //$NON-NLS-1$ public static final String PREFERENCE_TIME_LIMIT = "timeLimit"; //$NON-NLS-1$ public static final String PREFERENCE_COUNT_LIMIT = "countLimit"; //$NON-NLS-1$ public static final String PREFERENCE_SYNTAX_VALUEPEDITOR_RELATIONS = "syntaxValueProviderRelations"; //$NON-NLS-1$ public static final String PREFERENCE_ATTRIBUTE_VALUEEDITOR_RELATIONS = "attributeValueProviderRelations"; //$NON-NLS-1$ public static final String PREFERENCE_FORMAT_TABLE_ATTRIBUTEDELIMITER = "formatTableAttributeDelimiter"; //$NON-NLS-1$ public static final String PREFERENCE_FORMAT_TABLE_VALUEDELIMITER = "formatTableValueDelimiter"; //$NON-NLS-1$ public static final String PREFERENCE_FORMAT_TABLE_QUOTECHARACTER = "formatTableQuoteCharacter"; //$NON-NLS-1$ public static final String PREFERENCE_FORMAT_TABLE_LINESEPARATOR = "formatTableLineSeparator"; //$NON-NLS-1$ public static final String PREFERENCE_FORMAT_TABLE_BINARYENCODING = "formatTableBinaryEncoding"; //$NON-NLS-1$ public static final String PREFERENCE_SHOW_RAW_VALUES = "showRawValues"; //$NON-NLS-1$ public static final String PREFERENCE_BROWSER_SORT_BY = "browserSortBy"; //$NON-NLS-1$ public static final String PREFERENCE_BROWSER_SORT_ORDER = "browserSortOrder"; //$NON-NLS-1$ public static final String PREFERENCE_BROWSER_SORT_LIMIT = "browserSortLimit"; //$NON-NLS-1$ public static final String PREFERENCE_BROWSER_SORT_SEARCHES_ORDER = "browserSortSearchesOrder"; //$NON-NLS-1$ public static final String PREFERENCE_BROWSER_SORT_BOOKMARKS_ORDER = "browserSortBookmarksOrder"; //$NON-NLS-1$ public static final String PREFERENCE_BROWSER_LEAF_ENTRIES_FIRST = "browserLeafEntriesFirst"; //$NON-NLS-1$ public static final String PREFERENCE_BROWSER_CONTAINER_ENTRIES_FIRST = "browserContainerEntriesFirst"; //$NON-NLS-1$ public static final String PREFERENCE_BROWSER_META_ENTRIES_LAST = "browserMetaEntriesLast"; //$NON-NLS-1$ public static final String PREFERENCE_BROWSER_SHOW_QUICK_SEARCH = "browserShowQuickSearch"; //$NON-NLS-1$ public static final String PREFERENCE_BROWSER_QUICK_SEARCH_SUBTREE_SCOPE = "browserQuickSearchSubtreeScope"; //$NON-NLS-1$ public static final String PREFERENCE_BROWSER_SHOW_DIT = "browserShowDIT"; //$NON-NLS-1$ public static final String PREFERENCE_BROWSER_SHOW_SEARCHES = "browserShowSearches"; //$NON-NLS-1$ public static final String PREFERENCE_BROWSER_SHOW_BOOKMARKS = "browserShowBookmarks"; //$NON-NLS-1$ public static final String PREFERENCE_BROWSER_SHOW_DIRECTORY_META_ENTRIES = "browserShowDirectoryMetaEntries"; //$NON-NLS-1$ public static final String PREFERENCE_BROWSER_ENABLE_FOLDING = "browserEnableFolding"; //$NON-NLS-1$ public static final String PREFERENCE_BROWSER_FOLDING_SIZE = "browserFoldingSize"; //$NON-NLS-1$ public static final String PREFERENCE_BROWSER_EXPAND_BASE_ENTRIES = "browserExpandBaseEntries"; //$NON-NLS-1$ public static final String PREFERENCE_BROWSER_ENTRY_LABEL = "browserEntryLabel"; //$NON-NLS-1$ public static final String PREFERENCE_BROWSER_ENTRY_ABBREVIATE = "browserEntryAbbreviate"; //$NON-NLS-1$ public static final String PREFERENCE_BROWSER_ENTRY_ABBREVIATE_MAX_LENGTH = "browserentryAbbreviateMaxLength"; //$NON-NLS-1$ public static final String PREFERENCE_BROWSER_SEARCH_RESULT_LABEL = "browserSearchResultLabel"; //$NON-NLS-1$ public static final String PREFERENCE_BROWSER_SEARCH_RESULT_ABBREVIATE = "browserWearchResultAbbreviate"; //$NON-NLS-1$ public static final String PREFERENCE_BROWSER_SEARCH_RESULT_ABBREVIATE_MAX_LENGTH = "browserSearchResultAbbreviateMaxLength"; //$NON-NLS-1$ public static final String PREFERENCE_ENTRYEDITOR_AUTOSAVE_SINGLE_TAB = "entryeditorAutoSaveSingleTab"; //$NON-NLS-1$ public static final String PREFERENCE_ENTRYEDITOR_AUTOSAVE_MULTI_TAB = "entryeditorAutoSaveMultiTab"; //$NON-NLS-1$ public static final String PREFERENCE_ENTRYEDITOR_ENABLE_FOLDING = "entryeditorEnableFolding"; //$NON-NLS-1$ public static final String PREFERENCE_ENTRYEDITOR_FOLDING_THRESHOLD = "entryeditorFoldingThreshold"; //$NON-NLS-1$ public static final String PREFERENCE_ENTRYEDITOR_AUTO_EXPAND_FOLDED_ATTRIBUTES = "entryeditorAutoExpandFoldedAttributes"; //$NON-NLS-1$ public static final String PREFERENCE_ENTRYEDITOR_OBJECTCLASS_AND_MUST_ATTRIBUTES_FIRST = "entryeditorObjectClassAndMustAttributesFirst"; //$NON-NLS-1$ public static final String PREFERENCE_ENTRYEDITOR_OPERATIONAL_ATTRIBUTES_LAST = "entryeditorOperationalAttributesLast"; //$NON-NLS-1$ public static final String PREFERENCE_ENTRYEDITOR_DEFAULT_SORT_BY = "entryeditorDefaultSortBy"; //$NON-NLS-1$ public static final String PREFERENCE_ENTRYEDITOR_DEFAULT_SORT_ORDER = "entryeditorDefaultSortOrder"; //$NON-NLS-1$ public static final String PREFERENCE_OBJECTCLASS_COLOR = "objectClassColor"; //$NON-NLS-1$ public static final String PREFERENCE_OBJECTCLASS_FONT = "objectClassFont"; //$NON-NLS-1$ public static final String PREFERENCE_MUSTATTRIBUTE_COLOR = "mustAttributeColor"; //$NON-NLS-1$ public static final String PREFERENCE_MUSTATTRIBUTE_FONT = "mustAttributeFont"; //$NON-NLS-1$ public static final String PREFERENCE_MAYATTRIBUTE_COLOR = "mayAttributeColor"; //$NON-NLS-1$ public static final String PREFERENCE_MAYATTRIBUTE_FONT = "mayAttributeFont"; //$NON-NLS-1$ public static final String PREFERENCE_OPERATIONALATTRIBUTE_COLOR = "operationalAttributeColor"; //$NON-NLS-1$ public static final String PREFERENCE_OPERATIONALATTRIBUTE_FONT = "operationalAttributeFont"; //$NON-NLS-1$ public static final int SHOW_DN = 0; public static final int SHOW_RDN = 1; public static final int SHOW_RDN_VALUE = 2; public static final String PREFERENCEPAGEID_VALUEEDITORS = BrowserCommonActivator.getDefault() .getPluginProperties().getString( "PrefPage_ValueEditorsPreferencePage_id" ); //$NON-NLS-1$ public static final String IMG_TEMPLATE = "resources/icons/template.gif"; //$NON-NLS-1$ public static final String IMG_CLEAR = "resources/icons/clear.gif"; //$NON-NLS-1$ public static final String IMG_HEXEDITOR = "resources/icons/hexeditor.gif"; //$NON-NLS-1$ public static final String IMG_TEXTEDITOR = "resources/icons/texteditor.gif"; //$NON-NLS-1$ public static final String IMG_INPLACE_TEXTEDITOR = "resources/icons/inplace_texteditor.gif"; //$NON-NLS-1$ public static final String IMG_MULTIVALUEDEDITOR = "resources/icons/multivaluededitor.gif"; //$NON-NLS-1$ public static final String IMG_DNEDITOR = "resources/icons/dneditor.gif"; //$NON-NLS-1$ public static final String IMG_SORT = "resources/icons/sort.gif"; //$NON-NLS-1$ public static final String IMG_DIT = "resources/icons/dit.gif"; //$NON-NLS-1$ public static final String IMG_ENTRY = "resources/icons/entry_default.gif"; //$NON-NLS-1$ public static final String IMG_ENTRY_EDITOR = "resources/icons/entry_editor.gif"; //$NON-NLS-1$ public static final String IMG_ENTRY_ROOT = "resources/icons/entry_root.gif"; //$NON-NLS-1$ public static final String IMG_ENTRY_DC = "resources/icons/entry_dc.gif"; //$NON-NLS-1$ public static final String IMG_ENTRY_ORG = "resources/icons/entry_org.gif"; //$NON-NLS-1$ public static final String IMG_ENTRY_PERSON = "resources/icons/entry_person.gif"; //$NON-NLS-1$ public static final String IMG_ENTRY_GROUP = "resources/icons/entry_group.gif"; //$NON-NLS-1$ public static final String IMG_ENTRY_REF = "resources/icons/entry_ref.png"; //$NON-NLS-1$ public static final String IMG_ENTRY_ALIAS = "resources/icons/entry_alias.png"; //$NON-NLS-1$ public static final String IMG_SEARCHES = "resources/icons/searches.gif"; //$NON-NLS-1$ public static final String IMG_SEARCH = "resources/icons/search.gif"; //$NON-NLS-1$ public static final String IMG_QUICKSEARCH = "resources/icons/quicksearch.gif"; //$NON-NLS-1$ public static final String IMG_SUBTREE = "resources/icons/subtree.gif"; //$NON-NLS-1$ public static final String IMG_SEARCH_UNPERFORMED = "resources/icons/search_unperformed.gif"; //$NON-NLS-1$ public static final String IMG_BOOKMARKS = "resources/icons/bookmarks.gif"; //$NON-NLS-1$ public static final String IMG_BOOKMARK = "resources/icons/bookmark.gif"; //$NON-NLS-1$ public static final String IMG_BROWSER_SCHEMABROWSEREDITOR = "resources/icons/browser_schemabrowsereditor.gif"; //$NON-NLS-1$ public static final String IMG_CONNECTION_ADD = "resources/icons/connection_add.gif"; //$NON-NLS-1$ public static final String IMG_CONNECTION_CONNECTED = "resources/icons/connection_connected.gif"; //$NON-NLS-1$ public static final String IMG_CONNECTION_DISCONNECTED = "resources/icons/connection_disconnected.gif"; //$NON-NLS-1$ public static final String IMG_CONNECTION_CONNECT = "resources/icons/connection_connect.gif"; //$NON-NLS-1$ public static final String IMG_CONNECTION_DISCONNECT = "resources/icons/connection_disconnect.gif"; //$NON-NLS-1$ public static final String IMG_CONNECTION_WIZARD = "resources/icons/connection_wizard.gif"; //$NON-NLS-1$ public static final String IMG_REFRESH = "resources/icons/refresh.gif"; //$NON-NLS-1$ public static final String IMG_FILTER_DIT = "resources/icons/filter_dit.gif"; //$NON-NLS-1$ public static final String IMG_FILTER_EDITOR = "resources/icons/filtereditor.gif"; //$NON-NLS-1$ public static final String IMG_PARENT = "resources/icons/parent.gif"; //$NON-NLS-1$ public static final String IMG_UNFILTER_DIT = "resources/icons/unfilter_dit.gif"; //$NON-NLS-1$ public static final String IMG_FILTER = "resources/icons/filter.gif"; //$NON-NLS-1$ public static final String IMG_SORT_ASCENDING = "resources/icons/sort_ascending.gif"; //$NON-NLS-1$ public static final String IMG_SORT_DESCENDING = "resources/icons/sort_descending.gif"; //$NON-NLS-1$ public static final String IMG_VALUE_ADD = "resources/icons/value_add.gif"; //$NON-NLS-1$ public static final String IMG_ATTRIBUTE_ADD = "resources/icons/attribute_add.gif"; //$NON-NLS-1$ public static final String IMG_DELETE_ALL = "resources/icons/delete_all.gif"; //$NON-NLS-1$ public static final String IMG_ATD = "resources/icons/atd.png"; //$NON-NLS-1$ public static final String IMG_LSD = "resources/icons/lsd.png"; //$NON-NLS-1$ public static final String IMG_OCD = "resources/icons/ocd.png"; //$NON-NLS-1$ public static final String IMG_OCD_ABSTRACT = "resources/icons/ocd_abstract.gif"; //$NON-NLS-1$ public static final String IMG_OCD_AUXILIARY = "resources/icons/ocd_auxiliary.gif"; //$NON-NLS-1$ public static final String IMG_OCD_STRUCTURAL = "resources/icons/ocd_structural.gif"; //$NON-NLS-1$ public static final String IMG_MRD = "resources/icons/mrd.png"; //$NON-NLS-1$ public static final String IMG_ENTRY_WIZARD = "resources/icons/entry_wizard.gif"; //$NON-NLS-1$ public static final String IMG_TOP = "resources/icons/top.gif"; //$NON-NLS-1$ public static final String IMG_NEXT = "resources/icons/next.gif"; //$NON-NLS-1$ public static final String IMG_PREVIOUS = "resources/icons/previous.gif"; //$NON-NLS-1$ public static final String IMG_RENAME = "resources/icons/rename.gif"; //$NON-NLS-1$ public static final String IMG_SYNTAX_CHECKER = "resources/icons/syntax_checker.png"; //$NON-NLS-1$ public static final String IMG_COMPARATOR = "resources/icons/comparator.png"; //$NON-NLS-1$ public static final String IMG_NORMALIZER = "resources/icons/normalizer.png"; //$NON-NLS-1$ public static final String IMG_DIT_CONTENT_RULE = "resources/icons/dit_content_rule.png"; //$NON-NLS-1$ public static final String IMG_DIT_STRUCTURE_RULE = "resources/icons/dit_structure_rule.png"; //$NON-NLS-1$ public static final String IMG_NAME_FORM = "resources/icons/name_form.png"; //$NON-NLS-1$ public static final String CMD_ADD_ATTRIBUTE = BrowserCommonActivator.getDefault().getPluginProperties() .getString( "Cmd_AddAttribute_id" ); //$NON-NLS-1$ public static final String CMD_ADD_VALUE = BrowserCommonActivator.getDefault().getPluginProperties() .getString( "Cmd_AddValue_id" ); //$NON-NLS-1$ public static final String CMD_OPEN_SEARCH_RESULT = BrowserCommonActivator.getDefault().getPluginProperties() .getString( "Cmd_OpenSearchResult_id" ); //$NON-NLS-1$ public static final String CMD_COPY = BrowserCommonActivator.getDefault().getPluginProperties() .getString( "Cmd_Copy_id" ); //$NON-NLS-1$ public static final String CMD_PASTE = BrowserCommonActivator.getDefault().getPluginProperties() .getString( "Cmd_Paste_id" ); //$NON-NLS-1$ public static final String CMD_DELETE = BrowserCommonActivator.getDefault().getPluginProperties() .getString( "Cmd_Delete_id" ); //$NON-NLS-1$ public static final String CMD_PROPERTIES = BrowserCommonActivator.getDefault().getPluginProperties() .getString( "Cmd_Properties_id" ); //$NON-NLS-1$ public static final String CMD_FIND = BrowserCommonActivator.getDefault().getPluginProperties() .getString( "Cmd_Find_id" ); //$NON-NLS-1$ public static final String PROP_VALUE = "org.apache.directory.studio.ldapbrowser.ui.dialogs.properties.ValuePropertyPage"; //$NON-NLS-1$ public static final String PROP_ATTRIBUTE = "org.apache.directory.studio.ldapbrowser.ui.dialogs.properties.AttributePropertyPage"; //$NON-NLS-1$ public static final String PROP_SEARCH = "org.apache.directory.studio.ldapbrowser.ui.dialogs.properties.SearchPropertyPage"; //$NON-NLS-1$ public static final String PROP_BOOKMARK = "org.apache.directory.studio.ldapbrowser.ui.dialogs.properties.BookmarkPropertyPage"; //$NON-NLS-1$ public static final String PROP_ENTRY = "org.apache.directory.studio.ldapbrowser.ui.dialogs.properties.EntryPropertyPage"; //$NON-NLS-1$ public static final String DND_ENTRY_TRANSFER = "org.apache.directory.studio.ldapbrowser.entry"; //$NON-NLS-1$ public static final String DND_SEARCH_TRANSFER = "org.apache.directory.studio.ldapbrowser.search"; //$NON-NLS-1$ public static final String DND_VALUES_TRANSFER = "org.apache.directory.studio.ldapbrowser.value"; //$NON-NLS-1$ public static final String WIZARD_ATTRIBUTE_WIZARD = PLUGIN_ID + ".wizards.AttributeWizard"; //$NON-NLS-1$ public static final String WIZARD_NEW_ENTRY_WIZARD = PLUGIN_ID + ".wizards.NewEntryWizard"; //$NON-NLS-1$ public static final String WIZARD_NEW_CONTEXT_ENTRY_WIZARD = "org.apache.directory.studio.ldapbrowser.common.wizards.NewContextEntryWizard"; //$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/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/BrowserCommonPreferencesInitializer.java
plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/BrowserCommonPreferencesInitializer.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.ldapbrowser.common; import java.util.ArrayList; import java.util.Collection; import org.apache.directory.api.ldap.model.constants.SchemaConstants; import org.apache.directory.studio.ldapbrowser.core.BrowserCoreConstants; import org.apache.directory.studio.ldapbrowser.core.BrowserCorePlugin; import org.apache.directory.studio.ldapbrowser.core.model.schema.AttributeValueEditorRelation; import org.apache.directory.studio.ldapbrowser.core.model.schema.ObjectClassIconPair; import org.apache.directory.studio.ldapbrowser.core.model.schema.SyntaxValueEditorRelation; import org.apache.directory.studio.valueeditors.ValueEditorManager; import org.apache.directory.studio.valueeditors.ValueEditorManager.ValueEditorExtension; import org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer; import org.eclipse.jface.preference.IPreferenceStore; import org.eclipse.jface.preference.PreferenceConverter; import org.eclipse.swt.SWT; import org.eclipse.swt.graphics.FontData; import org.eclipse.swt.widgets.Display; /** * This class is used to set default preference values. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class BrowserCommonPreferencesInitializer extends AbstractPreferenceInitializer { /** * {@inheritDoc} */ public void initializeDefaultPreferences() { IPreferenceStore store = BrowserCommonActivator.getDefault().getPreferenceStore(); // Common store.setDefault( BrowserCommonConstants.PREFERENCE_COUNT_LIMIT, 1000 ); store.setDefault( BrowserCommonConstants.PREFERENCE_TIME_LIMIT, 0 ); // Fonts FontData[] fontData = Display.getDefault().getSystemFont().getFontData(); FontData fontDataNormal = new FontData( fontData[0].getName(), fontData[0].getHeight(), SWT.NORMAL ); FontData fontDataItalic = new FontData( fontData[0].getName(), fontData[0].getHeight(), SWT.ITALIC ); FontData fontDataBold = new FontData( fontData[0].getName(), fontData[0].getHeight(), SWT.BOLD ); FontData fontDataBoldItalic = new FontData( fontData[0].getName(), fontData[0].getHeight(), SWT.BOLD | SWT.ITALIC ); // Attributes colors and fonts store.setDefault( BrowserCommonConstants.PREFERENCE_OBJECTCLASS_COLOR, IPreferenceStore.STRING_DEFAULT_DEFAULT ); PreferenceConverter.setDefault( store, BrowserCommonConstants.PREFERENCE_OBJECTCLASS_FONT, fontDataBoldItalic ); store.setDefault( BrowserCommonConstants.PREFERENCE_MUSTATTRIBUTE_COLOR, IPreferenceStore.STRING_DEFAULT_DEFAULT ); PreferenceConverter.setDefault( store, BrowserCommonConstants.PREFERENCE_MUSTATTRIBUTE_FONT, fontDataBold ); store.setDefault( BrowserCommonConstants.PREFERENCE_MAYATTRIBUTE_COLOR, IPreferenceStore.STRING_DEFAULT_DEFAULT ); PreferenceConverter.setDefault( store, BrowserCommonConstants.PREFERENCE_MAYATTRIBUTE_FONT, fontDataNormal ); store.setDefault( BrowserCommonConstants.PREFERENCE_MAYATTRIBUTE_COLOR, IPreferenceStore.STRING_DEFAULT_DEFAULT ); PreferenceConverter.setDefault( store, BrowserCommonConstants.PREFERENCE_OPERATIONALATTRIBUTE_FONT, fontDataItalic ); // Attributes store.setDefault( BrowserCommonConstants.PREFERENCE_SHOW_RAW_VALUES, false ); // Value Editors Collection<AttributeValueEditorRelation> avprs = new ArrayList<AttributeValueEditorRelation>(); Collection<SyntaxValueEditorRelation> svprs = new ArrayList<SyntaxValueEditorRelation>(); Collection<ValueEditorExtension> valueEditorExtensions = ValueEditorManager.getValueEditorExtensions(); for ( ValueEditorExtension vee : valueEditorExtensions ) { for ( String attributeType : vee.attributeTypes ) { AttributeValueEditorRelation aver = new AttributeValueEditorRelation( attributeType, vee.className ); avprs.add( aver ); } for ( String syntaxOid : vee.syntaxOids ) { SyntaxValueEditorRelation sver = new SyntaxValueEditorRelation( syntaxOid, vee.className ); svprs.add( sver ); } } BrowserCommonActivator.getDefault().getValueEditorsPreferences().setDefaultAttributeValueEditorRelations( avprs.toArray( new AttributeValueEditorRelation[0] ) ); BrowserCommonActivator.getDefault().getValueEditorsPreferences().setDefaultSyntaxValueEditorRelations( svprs.toArray( new SyntaxValueEditorRelation[0] ) ); // Browser store.setDefault( BrowserCommonConstants.PREFERENCE_BROWSER_EXPAND_BASE_ENTRIES, false ); store.setDefault( BrowserCommonConstants.PREFERENCE_BROWSER_ENABLE_FOLDING, true ); store.setDefault( BrowserCommonConstants.PREFERENCE_BROWSER_FOLDING_SIZE, 100 ); store.setDefault( BrowserCommonConstants.PREFERENCE_BROWSER_ENTRY_LABEL, BrowserCommonConstants.SHOW_RDN ); store.setDefault( BrowserCommonConstants.PREFERENCE_BROWSER_ENTRY_ABBREVIATE, true ); store.setDefault( BrowserCommonConstants.PREFERENCE_BROWSER_ENTRY_ABBREVIATE_MAX_LENGTH, 50 ); store .setDefault( BrowserCommonConstants.PREFERENCE_BROWSER_SEARCH_RESULT_LABEL, BrowserCommonConstants.SHOW_DN ); store.setDefault( BrowserCommonConstants.PREFERENCE_BROWSER_SEARCH_RESULT_ABBREVIATE, true ); store.setDefault( BrowserCommonConstants.PREFERENCE_BROWSER_SEARCH_RESULT_ABBREVIATE_MAX_LENGTH, 50 ); store.setDefault( BrowserCommonConstants.PREFERENCE_BROWSER_SHOW_QUICK_SEARCH, true ); store.setDefault( BrowserCommonConstants.PREFERENCE_BROWSER_SHOW_DIT, true ); store.setDefault( BrowserCommonConstants.PREFERENCE_BROWSER_SHOW_SEARCHES, true ); store.setDefault( BrowserCommonConstants.PREFERENCE_BROWSER_SHOW_BOOKMARKS, true ); store.setDefault( BrowserCommonConstants.PREFERENCE_BROWSER_SHOW_DIRECTORY_META_ENTRIES, false ); store.setDefault( BrowserCommonConstants.PREFERENCE_BROWSER_SORT_BY, BrowserCoreConstants.SORT_BY_RDN_VALUE ); store.setDefault( BrowserCommonConstants.PREFERENCE_BROWSER_SORT_ORDER, BrowserCoreConstants.SORT_ORDER_ASCENDING ); store.setDefault( BrowserCommonConstants.PREFERENCE_BROWSER_SORT_SEARCHES_ORDER, BrowserCoreConstants.SORT_ORDER_ASCENDING ); store.setDefault( BrowserCommonConstants.PREFERENCE_BROWSER_SORT_BOOKMARKS_ORDER, BrowserCoreConstants.SORT_ORDER_ASCENDING ); store.setDefault( BrowserCommonConstants.PREFERENCE_BROWSER_SORT_LIMIT, 10000 ); store.setDefault( BrowserCommonConstants.PREFERENCE_BROWSER_LEAF_ENTRIES_FIRST, true ); store.setDefault( BrowserCommonConstants.PREFERENCE_BROWSER_CONTAINER_ENTRIES_FIRST, false ); store.setDefault( BrowserCommonConstants.PREFERENCE_BROWSER_META_ENTRIES_LAST, true ); // default icons ObjectClassIconPair[] objectClassIcons = new ObjectClassIconPair[] { new ObjectClassIconPair( new String[] { SchemaConstants.PERSON_OC_OID, SchemaConstants.ORGANIZATIONAL_PERSON_OC_OID, SchemaConstants.INET_ORG_PERSON_OC_OID }, BrowserCommonConstants.IMG_ENTRY_PERSON ), new ObjectClassIconPair( new String[] { SchemaConstants.POSIX_ACCOUNT_OC_OID }, BrowserCommonConstants.IMG_ENTRY_PERSON ), new ObjectClassIconPair( new String[] { SchemaConstants.ORGANIZATION_OC_OID }, BrowserCommonConstants.IMG_ENTRY_ORG ), new ObjectClassIconPair( new String[] { SchemaConstants.ORGANIZATIONAL_UNIT_OC_OID }, BrowserCommonConstants.IMG_ENTRY_ORG ), new ObjectClassIconPair( new String[] { SchemaConstants.COUNTRY_OC_OID }, BrowserCommonConstants.IMG_ENTRY_DC ), new ObjectClassIconPair( new String[] { SchemaConstants.LOCALITY_OC_OID }, BrowserCommonConstants.IMG_ENTRY_DC ), new ObjectClassIconPair( new String[] { SchemaConstants.DC_OBJECT_OC_OID }, BrowserCommonConstants.IMG_ENTRY_DC ), new ObjectClassIconPair( new String[] { SchemaConstants.DOMAIN_OC_OID }, BrowserCommonConstants.IMG_ENTRY_DC ), new ObjectClassIconPair( new String[] { SchemaConstants.GROUP_OF_NAMES_OC_OID }, BrowserCommonConstants.IMG_ENTRY_GROUP ), new ObjectClassIconPair( new String[] { SchemaConstants.GROUP_OF_UNIQUE_NAMES_OC_OID }, BrowserCommonConstants.IMG_ENTRY_GROUP ), new ObjectClassIconPair( new String[] { SchemaConstants.POSIX_GROUP_OC_OID }, BrowserCommonConstants.IMG_ENTRY_GROUP ), new ObjectClassIconPair( new String[] { SchemaConstants.SUBENTRY_OC_OID }, BrowserCommonConstants.IMG_BROWSER_SCHEMABROWSEREDITOR ), new ObjectClassIconPair( new String[] { SchemaConstants.REFERRAL_OC_OID }, BrowserCommonConstants.IMG_ENTRY_REF ), new ObjectClassIconPair( new String[] { SchemaConstants.ALIAS_OC_OID }, BrowserCommonConstants.IMG_ENTRY_ALIAS ), new ObjectClassIconPair( new String[] { SchemaConstants.META_SCHEMA_OC_OID }, BrowserCommonConstants.IMG_BROWSER_SCHEMABROWSEREDITOR ), new ObjectClassIconPair( new String[] { SchemaConstants.META_OBJECT_CLASS_OC_OID }, BrowserCommonConstants.IMG_OCD ), new ObjectClassIconPair( new String[] { SchemaConstants.META_ATTRIBUTE_TYPE_OC_OID }, BrowserCommonConstants.IMG_ATD ), new ObjectClassIconPair( new String[] { SchemaConstants.META_MATCHING_RULE_OC_OID }, BrowserCommonConstants.IMG_MRD ), new ObjectClassIconPair( new String[] { SchemaConstants.META_SYNTAX_CHECKER_OC_OID }, BrowserCommonConstants.IMG_SYNTAX_CHECKER ), new ObjectClassIconPair( new String[] { SchemaConstants.META_SYNTAX_OC_OID }, BrowserCommonConstants.IMG_LSD ), new ObjectClassIconPair( new String[] { SchemaConstants.META_COMPARATOR_OC_OID }, BrowserCommonConstants.IMG_COMPARATOR ), new ObjectClassIconPair( new String[] { SchemaConstants.META_NORMALIZER_OC_OID }, BrowserCommonConstants.IMG_NORMALIZER ), new ObjectClassIconPair( new String[] { SchemaConstants.META_DIT_CONTENT_RULE_OC_OID }, BrowserCommonConstants.IMG_DIT_CONTENT_RULE ), new ObjectClassIconPair( new String[] { SchemaConstants.META_DIT_STRUCTURE_RULE_OC_OID }, BrowserCommonConstants.IMG_DIT_STRUCTURE_RULE ), new ObjectClassIconPair( new String[] { SchemaConstants.META_NAME_FORM_OC_OID }, BrowserCommonConstants.IMG_NAME_FORM ), // Active Directory new ObjectClassIconPair( new String[] { "1.2.840.113556.1.5.9" }, BrowserCommonConstants.IMG_ENTRY_PERSON ), // User //$NON-NLS-1$ new ObjectClassIconPair( new String[] { "1.2.840.113556.1.5.8" }, BrowserCommonConstants.IMG_ENTRY_GROUP ), // Group //$NON-NLS-1$ new ObjectClassIconPair( new String[] { "1.2.840.113556.1.3.23" }, BrowserCommonConstants.IMG_ENTRY_ORG ), // Container //$NON-NLS-1$ new ObjectClassIconPair( new String[] { "1.2.840.113556.1.5.66", "1.2.840.113556.1.5.67" }, BrowserCommonConstants.IMG_ENTRY_DC ), // Domain, DomainDNS //$NON-NLS-1$ //$NON-NLS-2$ new ObjectClassIconPair( new String[] { "1.2.840.113556.1.3.13" }, BrowserCommonConstants.IMG_OCD ), // ClassSchema //$NON-NLS-1$ new ObjectClassIconPair( new String[] { "1.2.840.113556.1.3.14" }, BrowserCommonConstants.IMG_ATD ), // AttributeSchema //$NON-NLS-1$ }; BrowserCorePlugin.getDefault().getCorePreferences().setDefaultObjectClassIcons( objectClassIcons ); // Entry Editor store.setDefault( BrowserCommonConstants.PREFERENCE_ENTRYEDITOR_ENABLE_FOLDING, true ); store.setDefault( BrowserCommonConstants.PREFERENCE_ENTRYEDITOR_FOLDING_THRESHOLD, 10 ); store.setDefault( BrowserCommonConstants.PREFERENCE_ENTRYEDITOR_AUTO_EXPAND_FOLDED_ATTRIBUTES, false ); store.setDefault( BrowserCommonConstants.PREFERENCE_ENTRYEDITOR_AUTOSAVE_SINGLE_TAB, true ); store.setDefault( BrowserCommonConstants.PREFERENCE_ENTRYEDITOR_AUTOSAVE_MULTI_TAB, false ); store.setDefault( BrowserCommonConstants.PREFERENCE_ENTRYEDITOR_OBJECTCLASS_AND_MUST_ATTRIBUTES_FIRST, true ); store.setDefault( BrowserCommonConstants.PREFERENCE_ENTRYEDITOR_OPERATIONAL_ATTRIBUTES_LAST, true ); store.setDefault( BrowserCommonConstants.PREFERENCE_ENTRYEDITOR_DEFAULT_SORT_BY, BrowserCoreConstants.SORT_BY_ATTRIBUTE_DESCRIPTION ); store.setDefault( BrowserCommonConstants.PREFERENCE_ENTRYEDITOR_DEFAULT_SORT_ORDER, BrowserCoreConstants.SORT_ORDER_ASCENDING ); // Text Format store.setDefault( BrowserCommonConstants.PREFERENCE_FORMAT_TABLE_ATTRIBUTEDELIMITER, "\t" ); //$NON-NLS-1$ store.setDefault( BrowserCommonConstants.PREFERENCE_FORMAT_TABLE_VALUEDELIMITER, "|" ); //$NON-NLS-1$ store.setDefault( BrowserCommonConstants.PREFERENCE_FORMAT_TABLE_QUOTECHARACTER, "\"" ); //$NON-NLS-1$ store.setDefault( BrowserCommonConstants.PREFERENCE_FORMAT_TABLE_LINESEPARATOR, BrowserCoreConstants.LINE_SEPARATOR ); store.setDefault( BrowserCommonConstants.PREFERENCE_FORMAT_TABLE_BINARYENCODING, BrowserCoreConstants.BINARYENCODING_IGNORE ); } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/BrowserCommonActivator.java
plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/BrowserCommonActivator.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.ldapbrowser.common; import java.io.IOException; import java.net.URL; import java.util.PropertyResourceBundle; import org.apache.directory.studio.connection.core.event.EventRunner; import org.apache.directory.studio.connection.ui.UiThreadEventRunner; import org.eclipse.core.runtime.FileLocator; import org.eclipse.core.runtime.Path; import org.eclipse.core.runtime.Status; import org.eclipse.jface.resource.ColorRegistry; import org.eclipse.jface.resource.FontRegistry; import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.jface.text.templates.ContextTypeRegistry; import org.eclipse.jface.text.templates.GlobalTemplateVariables; import org.eclipse.jface.text.templates.persistence.TemplateStore; import org.eclipse.swt.graphics.Color; import org.eclipse.swt.graphics.Font; import org.eclipse.swt.graphics.FontData; import org.eclipse.swt.graphics.Image; import org.eclipse.swt.graphics.RGB; import org.eclipse.ui.PlatformUI; import org.eclipse.ui.editors.text.templates.ContributionContextTypeRegistry; import org.eclipse.ui.editors.text.templates.ContributionTemplateStore; import org.eclipse.ui.plugin.AbstractUIPlugin; import org.osgi.framework.BundleContext; /** * The activator class controls the plug-in life cycle */ public class BrowserCommonActivator extends AbstractUIPlugin { /** The shared instance */ private static BrowserCommonActivator plugin; /** The font registry */ private FontRegistry fontRegistry; /** The color registry */ private ColorRegistry colorRegistry; /** The value editor preferences */ private ValueEditorsPreferences valueEditorPreferences; /** The filter template store. */ private ContributionTemplateStore filterTemplateStore; /** The filter template context type registry. */ private ContributionContextTypeRegistry filterTemplateContextTypeRegistry; /** The event runner. */ private EventRunner eventRunner; /** The plugin properties */ private PropertyResourceBundle properties; /** * The constructor */ public BrowserCommonActivator() { plugin = this; } /** * {@inheritDoc} */ public void start( BundleContext context ) throws Exception { super.start( context ); if ( eventRunner == null ) { eventRunner = new UiThreadEventRunner(); } if ( fontRegistry == null ) { fontRegistry = new FontRegistry( PlatformUI.getWorkbench().getDisplay() ); } if ( colorRegistry == null ) { colorRegistry = new ColorRegistry( PlatformUI.getWorkbench().getDisplay() ); } valueEditorPreferences = new ValueEditorsPreferences(); if ( filterTemplateContextTypeRegistry == null ) { filterTemplateContextTypeRegistry = new ContributionContextTypeRegistry(); filterTemplateContextTypeRegistry.addContextType( BrowserCommonConstants.FILTER_TEMPLATE_ID ); filterTemplateContextTypeRegistry.getContextType( BrowserCommonConstants.FILTER_TEMPLATE_ID ).addResolver( new GlobalTemplateVariables.Cursor() ); } if ( filterTemplateStore == null ) { filterTemplateStore = new ContributionTemplateStore( getFilterTemplateContextTypeRegistry(), getPreferenceStore(), "templates" ); //$NON-NLS-1$ try { filterTemplateStore.load(); } catch ( IOException e ) { e.printStackTrace(); } } } /** * {@inheritDoc} */ public void stop( BundleContext context ) throws Exception { plugin = null; super.stop( context ); if ( eventRunner != null ) { eventRunner = null; } if ( fontRegistry != null ) { fontRegistry = null; } if ( colorRegistry != null ) { colorRegistry = null; } if ( filterTemplateContextTypeRegistry != null ) { filterTemplateContextTypeRegistry = null; } if ( filterTemplateStore != null ) { try { filterTemplateStore.save(); } catch ( IOException e ) { e.printStackTrace(); } filterTemplateStore = null; } } /** * Returns the shared instance * * @return the shared instance */ public static BrowserCommonActivator getDefault() { return plugin; } /** * Use this method to get SWT images. Use the IMG_ constants from * BrowserWidgetsConstants for the key. * * @param key * The key (relative path to the image im filesystem) * @return The image discriptor or null */ public ImageDescriptor getImageDescriptor( String key ) { if ( key != null ) { URL url = FileLocator.find( getBundle(), new Path( key ), null ); if ( url != null ) return ImageDescriptor.createFromURL( url ); else return null; } else { return null; } } /** * Use this method to get SWT images. Use the IMG_ constants from * BrowserWidgetsConstants for the key. A ImageRegistry is used to manage the * the key->Image mapping. * <p> * Note: Don't dispose the returned SWT Image. It is disposed * automatically when the plugin is stopped. * * @param key * The key (relative path to the image im filesystem) * @return The SWT Image or null * @see BrowserCommonConstants */ public Image getImage( String key ) { Image image = getImageRegistry().get( key ); if ( image == null ) { ImageDescriptor id = getImageDescriptor( key ); if ( id != null ) { image = id.createImage(); getImageRegistry().put( key, image ); } } return image; } /** * Use this method to get SWT fonts. A FontRegistry is used to manage * the FontData[]->Font mapping. * <p> * Note: Don't dispose the returned SWT Font. It is disposed * automatically when the plugin is stopped. * * @param fontData * the font data * @return The SWT Font */ public Font getFont( FontData[] fontData ) { if ( !fontRegistry.hasValueFor( fontData[0].toString() ) ) { fontRegistry.put( fontData[0].toString(), fontData ); } return fontRegistry.get( fontData[0].toString() ); } /** * Use this method to get SWT colors. A ColorRegistry is used to manage * the RGB->Color mapping. * <p> * Note: Don't dispose the returned color. It is disposed automatically * when the plugin is stopped. * * @param rgb the rgb color data * @return The SWT Color */ public Color getColor( RGB rgb ) { if ( !colorRegistry.hasValueFor( rgb.toString() ) ) { colorRegistry.put( rgb.toString(), rgb ); } return colorRegistry.get( rgb.toString() ); } /** * Gets the value editors preferences. * * @return the value editors preferences */ public ValueEditorsPreferences getValueEditorsPreferences() { return valueEditorPreferences; } /** * * @return The filter template store */ public TemplateStore getFilterTemplateStore() { return filterTemplateStore; } /** * * @return The filter template context type registry */ public ContextTypeRegistry getFilterTemplateContextTypeRegistry() { return filterTemplateContextTypeRegistry; } /** * Gets the event runner. * * @return the event runner */ public EventRunner getEventRunner() { return eventRunner; } /** * Gets the plugin properties. * * @return * the plugin properties */ public PropertyResourceBundle getPluginProperties() { if ( properties == null ) { try { properties = new PropertyResourceBundle( FileLocator.openStream( this.getBundle(), new Path( "plugin.properties" ), false ) ); //$NON-NLS-1$ } catch ( IOException e ) { getLog().log( new Status( Status.ERROR, "org.apache.directory.studio.ldapbrowser.common", Status.OK, //$NON-NLS-1$ "Unable to get the plugin properties.", e ) ); //$NON-NLS-1$ } } return properties; } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/ValueEditorsPreferences.java
plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/ValueEditorsPreferences.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.ldapbrowser.common; import java.util.HashMap; import java.util.Map; import org.apache.directory.api.util.Strings; import org.apache.directory.studio.ldapbrowser.core.model.schema.AttributeValueEditorRelation; import org.apache.directory.studio.ldapbrowser.core.model.schema.SyntaxValueEditorRelation; import org.apache.directory.studio.ldapbrowser.core.utils.Utils; import org.eclipse.jface.preference.IPreferenceStore; /** * This class is used to manage and access the preferences of the Value Editors Plugin. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class ValueEditorsPreferences { /** The attribute value editor cache. */ private Map<String, String> attributeValueEditorCache; /** The syntax value editor cache. */ private Map<String, String> syntaxValueEditorCache; /** * Gets a Map containing all the Attribute Value Editors. * * @return * a Map containing all the Attribute Value Editors */ public Map<String, String> getAttributeValueEditorMap() { if ( attributeValueEditorCache == null ) { attributeValueEditorCache = new HashMap<String, String>(); AttributeValueEditorRelation[] relations = getAttributeValueEditorRelations(); for ( int i = 0; i < relations.length; i++ ) { if ( relations[i].getAttributeNumericOidOrType() != null ) { attributeValueEditorCache.put( Strings.toLowerCase( relations[i].getAttributeNumericOidOrType() ), relations[i].getValueEditorClassName() ); } } } return attributeValueEditorCache; } /** * Gets an array containing all the Attribute Value Editor Relations. * * @return * an array containing all the Attribute Value Editor Relations */ public AttributeValueEditorRelation[] getAttributeValueEditorRelations() { IPreferenceStore store = BrowserCommonActivator.getDefault().getPreferenceStore(); String s = store.getString( BrowserCommonConstants.PREFERENCE_ATTRIBUTE_VALUEEDITOR_RELATIONS ); // Migration issue from 1.0.1 to 1.1.0 (DIRSTUDIO-287): class AttributeValueProviderRelation // was renamed to AttributeValueEditorRelation, to be able to load the old configuration it // is necessary to replace the old class name with the new class name. s = s.replaceAll( "AttributeValueProviderRelation", "AttributeValueEditorRelation" ); //$NON-NLS-1$ //$NON-NLS-2$ s = s.replaceAll( "valueProviderClassname", "valueEditorClassName" ); //$NON-NLS-1$ //$NON-NLS-2$ AttributeValueEditorRelation[] aver = ( AttributeValueEditorRelation[] ) Utils.deserialize( s ); return aver; } /** * Sets the Attribute Value Editor Relations. * * @param attributeValueEditorRelations * an array containing all the Attribute Value Editor Relations */ public void setAttributeValueEditorRelations( AttributeValueEditorRelation[] attributeValueEditorRelations ) { store( BrowserCommonConstants.PREFERENCE_ATTRIBUTE_VALUEEDITOR_RELATIONS, attributeValueEditorRelations ); attributeValueEditorCache = null; } /** * Gets the default Attribute Value Editor Relations. * * @return * an array containing all the default Attribute Value Editor Relations */ public AttributeValueEditorRelation[] getDefaultAttributeValueEditorRelations() { IPreferenceStore store = BrowserCommonActivator.getDefault().getPreferenceStore(); String s = store.getDefaultString( BrowserCommonConstants.PREFERENCE_ATTRIBUTE_VALUEEDITOR_RELATIONS ); // Migration issue from 1.0.1 to 1.1.0 (DIRSTUDIO-287): class AttributeValueProviderRelation // was renamed to AttributeValueEditorRelation, to be able to load the old configuration it // is necessary to replace the old class name with the new class name. s = s.replaceAll( "AttributeValueProviderRelation", "AttributeValueEditorRelation" ); //$NON-NLS-1$ //$NON-NLS-2$ s = s.replaceAll( "valueProviderClassname", "valueEditorClassName" ); //$NON-NLS-1$ //$NON-NLS-2$ AttributeValueEditorRelation[] aver = ( AttributeValueEditorRelation[] ) Utils.deserialize( s ); return aver; } /** * Sets the default Attribute Value Editor Relations. * * @param attributeValueEditorRelations * an array containing all the default Attribute Value Editor Relations */ public void setDefaultAttributeValueEditorRelations( AttributeValueEditorRelation[] attributeValueEditorRelations ) { storeDefault( BrowserCommonConstants.PREFERENCE_ATTRIBUTE_VALUEEDITOR_RELATIONS, attributeValueEditorRelations ); } /** * Gets a Map containing all the Syntax Value Editors. * * @return * a Map containing all the Syntax Value Editors */ public Map<String, String> getSyntaxValueEditorMap() { if ( syntaxValueEditorCache == null ) { syntaxValueEditorCache = new HashMap<String, String>(); SyntaxValueEditorRelation[] relations = getSyntaxValueEditorRelations(); for ( int i = 0; i < relations.length; i++ ) { if ( relations[i].getSyntaxOID() != null ) { syntaxValueEditorCache.put( Strings.toLowerCase( relations[i].getSyntaxOID() ), relations[i] .getValueEditorClassName() ); } } } return syntaxValueEditorCache; } /** * Sets the Syntax Value Editor Relations. * * @param syntaxValueEditorRelations * an array containing the Syntax Value Editor Relations to set */ public void setSyntaxValueEditorRelations( SyntaxValueEditorRelation[] syntaxValueEditorRelations ) { store( BrowserCommonConstants.PREFERENCE_SYNTAX_VALUEPEDITOR_RELATIONS, syntaxValueEditorRelations ); syntaxValueEditorCache = null; } /** * Gets an array containing all the Syntax Value Editor Relations * * @return * an array containing all the Syntax Value Editor Relations */ public SyntaxValueEditorRelation[] getSyntaxValueEditorRelations() { IPreferenceStore store = BrowserCommonActivator.getDefault().getPreferenceStore(); String s = store.getString( BrowserCommonConstants.PREFERENCE_SYNTAX_VALUEPEDITOR_RELATIONS ); // Migration issue from 1.0.1 to 1.1.0 (DIRSTUDIO-287): class SyntaxValueProviderRelation // was renamed to SyntaxValueEditorRelation, to be able to load the old configuration it // is necessary to replace the old class name with the new class name. s = s.replaceAll( "SyntaxValueProviderRelation", "SyntaxValueEditorRelation" ); //$NON-NLS-1$ //$NON-NLS-2$ s = s.replaceAll( "valueProviderClassname", "valueEditorClassName" ); //$NON-NLS-1$ //$NON-NLS-2$ SyntaxValueEditorRelation[] sver = ( SyntaxValueEditorRelation[] ) Utils.deserialize( s ); return sver; } /** * Gets an array containing all the default Syntax Value Editor Relations * * @return * an array containing all the default Syntax Value Editor Relations */ public SyntaxValueEditorRelation[] getDefaultSyntaxValueEditorRelations() { IPreferenceStore store = BrowserCommonActivator.getDefault().getPreferenceStore(); String s = store.getDefaultString( BrowserCommonConstants.PREFERENCE_SYNTAX_VALUEPEDITOR_RELATIONS ); // Migration issue from 1.0.1 to 1.1.0 (DIRSTUDIO-287): class SyntaxValueProviderRelation // was renamed to SyntaxValueEditorRelation, to be able to load the old configuration it // is necessary to replace the old class name with the new class name. s = s.replaceAll( "SyntaxValueProviderRelation", "SyntaxValueEditorRelation" ); //$NON-NLS-1$ //$NON-NLS-2$ s = s.replaceAll( "valueProviderClassname", "valueEditorClassName" ); //$NON-NLS-1$ //$NON-NLS-2$ SyntaxValueEditorRelation[] sver = ( SyntaxValueEditorRelation[] ) Utils.deserialize( s ); return sver; } /** * Sets the default Syntax Value Editor Relations. * * @param syntaxValueEditorRelations * an array containing the default Syntax Value Editor Relations to set */ public void setDefaultSyntaxValueEditorRelations( SyntaxValueEditorRelation[] syntaxValueEditorRelations ) { storeDefault( BrowserCommonConstants.PREFERENCE_SYNTAX_VALUEPEDITOR_RELATIONS, syntaxValueEditorRelations ); } /** * Stores the current value of the string-valued property with the given name. * * @param key * the name of the property * @param o * the new current value of the property */ private static void store( String key, Object o ) { IPreferenceStore store = BrowserCommonActivator.getDefault().getPreferenceStore(); String s = Utils.serialize( o ); store.setValue( key, s ); } /** * Stores the default value for the string-valued property with the given name. * * @param key * the name of the property * @param o * the new default value for the property */ private static void storeDefault( String key, Object o ) { IPreferenceStore store = BrowserCommonActivator.getDefault().getPreferenceStore(); String s = Utils.serialize( o ); store.setDefault( key, s ); } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/dnd/EntryTransfer.java
plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/dnd/EntryTransfer.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.ldapbrowser.common.dnd; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.DataInputStream; import java.io.DataOutputStream; import java.io.IOException; import java.util.ArrayList; import java.util.List; import org.apache.directory.api.ldap.model.name.Dn; import org.apache.directory.studio.ldapbrowser.common.BrowserCommonConstants; import org.apache.directory.studio.ldapbrowser.core.BrowserConnectionManager; import org.apache.directory.studio.ldapbrowser.core.BrowserCorePlugin; import org.apache.directory.studio.ldapbrowser.core.model.IBrowserConnection; import org.apache.directory.studio.ldapbrowser.core.model.IEntry; import org.eclipse.swt.dnd.ByteArrayTransfer; import org.eclipse.swt.dnd.Transfer; import org.eclipse.swt.dnd.TransferData; /** * A {@link Transfer} that could be used to transfer {@link IEntry} objects. * Note that only the connection id and entry's Dn is converted to a platform specific * representation, not the complete object. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class EntryTransfer extends ByteArrayTransfer { /** The Constant TYPENAME. */ private static final String TYPENAME = BrowserCommonConstants.DND_ENTRY_TRANSFER; /** The Constant TYPEID. */ private static final int TYPEID = registerType( TYPENAME ); /** The instance. */ private static EntryTransfer instance = new EntryTransfer(); /** * Gets the instance. * * @return the instance */ public static EntryTransfer getInstance() { return instance; } /** * Creates a new instance of EntryTransfer. */ private EntryTransfer() { } /** * {@inheritDoc} * * This implementation only accepts {@link IEntry} objects. * It just converts the id of the connection and the entry's Dn * to the platform specific representation. */ public void javaToNative( Object object, TransferData transferData ) { if ( !( object instanceof IEntry[] ) ) { return; } if ( isSupportedType( transferData ) ) { IEntry[] entries = ( IEntry[] ) object; try { ByteArrayOutputStream out = new ByteArrayOutputStream(); DataOutputStream writeOut = new DataOutputStream( out ); for ( int i = 0; i < entries.length; i++ ) { byte[] connectionId = entries[i].getBrowserConnection().getConnection().getId().getBytes( "UTF-8" ); //$NON-NLS-1$ writeOut.writeInt( connectionId.length ); writeOut.write( connectionId ); byte[] dn = entries[i].getDn().getName().getBytes( "UTF-8" ); //$NON-NLS-1$ writeOut.writeInt( dn.length ); writeOut.write( dn ); } byte[] buffer = out.toByteArray(); writeOut.close(); super.javaToNative( buffer, transferData ); } catch ( IOException e ) { } } } /** * {@inheritDoc} * * This implementation just converts the platform specific representation * to the connection id and entry Dn and invokes * {@link BrowserConnectionManager#getBrowserConnectionById(String)} to get the * {@link IBrowserConnection} object and {@link IBrowserConnection#getEntryFromCache(org.apache.directory.api.ldap.model.name.Dn)} * to get the {@link IEntry} object. */ public Object nativeToJava( TransferData transferData ) { try { if ( isSupportedType( transferData ) ) { byte[] buffer = ( byte[] ) super.nativeToJava( transferData ); if ( buffer == null ) { return null; } List<IEntry> entryList = new ArrayList<IEntry>(); try { IBrowserConnection connection = null; ByteArrayInputStream in = new ByteArrayInputStream( buffer ); DataInputStream readIn = new DataInputStream( in ); do { if ( readIn.available() > 1 ) { int size = readIn.readInt(); byte[] connectionId = new byte[size]; readIn.read( connectionId ); connection = BrowserCorePlugin.getDefault().getConnectionManager() .getBrowserConnectionById( new String( connectionId, "UTF-8" ) ); //$NON-NLS-1$ } IEntry entry = null; if ( readIn.available() > 1 && connection != null ) { int size = readIn.readInt(); byte[] dn = new byte[size]; readIn.read( dn ); entry = connection.getEntryFromCache( new Dn( new String( dn, "UTF-8" ) ) ); //$NON-NLS-1$ } else { return null; } if ( entry != null ) { entryList.add( entry ); } } while ( readIn.available() > 1 ); readIn.close(); } catch ( IOException ex ) { return null; } return entryList.isEmpty() ? null : entryList.toArray( new IEntry[0] ); } } catch ( Exception e ) { e.printStackTrace(); } return null; } /** * {@inheritDoc} */ protected String[] getTypeNames() { return new String[] { TYPENAME }; } /** * {@inheritDoc} */ protected int[] getTypeIds() { return new int[] { TYPEID }; } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/dnd/SearchTransfer.java
plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/dnd/SearchTransfer.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.ldapbrowser.common.dnd; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.DataInputStream; import java.io.DataOutputStream; import java.io.IOException; import java.util.ArrayList; import java.util.List; import org.apache.directory.studio.ldapbrowser.common.BrowserCommonConstants; import org.apache.directory.studio.ldapbrowser.core.BrowserConnectionManager; import org.apache.directory.studio.ldapbrowser.core.BrowserCorePlugin; import org.apache.directory.studio.ldapbrowser.core.model.IBrowserConnection; import org.apache.directory.studio.ldapbrowser.core.model.ISearch; import org.eclipse.swt.dnd.ByteArrayTransfer; import org.eclipse.swt.dnd.Transfer; import org.eclipse.swt.dnd.TransferData; /** * A {@link Transfer} that could be used to transfer {@link ISearch} objects. * Note that only the connection id and search name is converted to a platform specific * representation, not the complete object. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class SearchTransfer extends ByteArrayTransfer { /** The Constant TYPENAME. */ private static final String TYPENAME = BrowserCommonConstants.DND_SEARCH_TRANSFER; /** The Constant TYPEID. */ private static final int TYPEID = registerType( TYPENAME ); /** The instance. */ private static SearchTransfer instance = new SearchTransfer(); /** * Creates a new instance of SearchTransfer. */ private SearchTransfer() { } /** * Gets the instance. * * @return the instance */ public static SearchTransfer getInstance() { return instance; } /** * {@inheritDoc} * * This implementation only accepts {@link ISearch} objects. * It just converts the id of the connection and the name of the search * to the platform specific representation. */ public void javaToNative( Object object, TransferData transferData ) { if ( !( object instanceof ISearch[] ) ) { return; } if ( isSupportedType( transferData ) ) { ISearch[] searches = ( ISearch[] ) object; try { ByteArrayOutputStream out = new ByteArrayOutputStream(); DataOutputStream writeOut = new DataOutputStream( out ); for ( ISearch search : searches ) { byte[] connectionId = search.getBrowserConnection().getConnection().getId().getBytes( "UTF-8" ); //$NON-NLS-1$ writeOut.writeInt( connectionId.length ); writeOut.write( connectionId ); byte[] searchName = search.getName().getBytes( "UTF-8" ); //$NON-NLS-1$ writeOut.writeInt( searchName.length ); writeOut.write( searchName ); } byte[] buffer = out.toByteArray(); writeOut.close(); super.javaToNative( buffer, transferData ); } catch ( IOException e ) { } } } /** * {@inheritDoc} * * This implementation just converts the platform specific representation * to the connection id and search name and invokes * {@link BrowserConnectionManager#getBrowserConnectionById(String)} to get the * {@link IBrowserConnection} object and {@link IBrowserConnection#getSearchManager()} * to get the {@link ISearch} object. */ public Object nativeToJava( TransferData transferData ) { try { if ( isSupportedType( transferData ) ) { byte[] buffer = ( byte[] ) super.nativeToJava( transferData ); if ( buffer == null ) { return null; } List<ISearch> searchList = new ArrayList<ISearch>(); try { IBrowserConnection connection = null; ByteArrayInputStream in = new ByteArrayInputStream( buffer ); DataInputStream readIn = new DataInputStream( in ); do { if ( readIn.available() > 1 ) { int size = readIn.readInt(); byte[] connectionId = new byte[size]; readIn.read( connectionId ); connection = BrowserCorePlugin.getDefault().getConnectionManager() .getBrowserConnectionById( new String( connectionId, "UTF-8" ) ); //$NON-NLS-1$ } ISearch search = null; if ( readIn.available() > 1 && connection != null ) { int size = readIn.readInt(); byte[] searchName = new byte[size]; readIn.read( searchName ); search = connection.getSearchManager().getSearch( new String( searchName, "UTF-8" ) ); //$NON-NLS-1$ } else { return null; } if ( search != null ) { searchList.add( search ); } } while ( readIn.available() > 1 ); readIn.close(); } catch ( IOException ex ) { return null; } return searchList.isEmpty() ? null : searchList.toArray( new ISearch[0] ); } } catch ( Exception e ) { e.printStackTrace(); } return null; } /** * {@inheritDoc} */ protected String[] getTypeNames() { return new String[] { TYPENAME }; } /** * {@inheritDoc} */ protected int[] getTypeIds() { return new int[] { TYPEID }; } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/dnd/ValuesTransfer.java
plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/dnd/ValuesTransfer.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.ldapbrowser.common.dnd; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.DataInputStream; import java.io.DataOutputStream; import java.io.IOException; import java.util.ArrayList; import java.util.List; import org.apache.directory.api.ldap.model.name.Dn; import org.apache.directory.studio.ldapbrowser.common.BrowserCommonConstants; import org.apache.directory.studio.ldapbrowser.core.BrowserCorePlugin; import org.apache.directory.studio.ldapbrowser.core.model.IAttribute; import org.apache.directory.studio.ldapbrowser.core.model.IBrowserConnection; import org.apache.directory.studio.ldapbrowser.core.model.IEntry; import org.apache.directory.studio.ldapbrowser.core.model.IValue; import org.eclipse.swt.dnd.ByteArrayTransfer; import org.eclipse.swt.dnd.Transfer; import org.eclipse.swt.dnd.TransferData; /** * A {@link Transfer} that could be used to transfer {@link IValue} objects. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class ValuesTransfer extends ByteArrayTransfer { /** The Constant TYPENAME. */ private static final String TYPENAME = BrowserCommonConstants.DND_VALUES_TRANSFER; /** The Constant TYPEID. */ private static final int TYPEID = registerType( TYPENAME ); /** The instance. */ private static ValuesTransfer instance = new ValuesTransfer(); /** * Gets the instance. * * @return the instance */ public static ValuesTransfer getInstance() { return instance; } /** * Creates a new instance of ValuesTransfer. */ private ValuesTransfer() { } /** * {@inheritDoc} * * This implementation only accepts {@link IValue} objects. * It converts the id of the connection, the entry's Dn, the * attribute description and the value to the platform specific * representation. */ public void javaToNative( Object object, TransferData transferData ) { if ( !( object instanceof IValue[] ) ) { return; } if ( isSupportedType( transferData ) ) { IValue[] values = ( IValue[] ) object; try { ByteArrayOutputStream out = new ByteArrayOutputStream(); DataOutputStream writeOut = new DataOutputStream( out ); for ( int i = 0; i < values.length; i++ ) { byte[] connectionId = values[i].getAttribute().getEntry().getBrowserConnection().getConnection() .getId().getBytes( "UTF-8" ); //$NON-NLS-1$ writeOut.writeInt( connectionId.length ); writeOut.write( connectionId ); byte[] dn = values[i].getAttribute().getEntry().getDn().getName().getBytes( "UTF-8" ); //$NON-NLS-1$ writeOut.writeInt( dn.length ); writeOut.write( dn ); byte[] attributeName = values[i].getAttribute().getDescription().getBytes( "UTF-8" ); //$NON-NLS-1$ writeOut.writeInt( attributeName.length ); writeOut.write( attributeName ); if ( values[i].isString() ) { byte[] value = values[i].getStringValue().getBytes( "UTF-8" ); //$NON-NLS-1$ writeOut.writeBoolean( true ); writeOut.writeInt( value.length ); writeOut.write( value ); } else if ( values[i].isBinary() ) { byte[] value = values[i].getBinaryValue(); writeOut.writeBoolean( false ); writeOut.writeInt( value.length ); writeOut.write( value ); } } byte[] buffer = out.toByteArray(); writeOut.close(); super.javaToNative( buffer, transferData ); } catch ( IOException e ) { } } } /** * {@inheritDoc} * * This implementation converts the platform specific representation * to the connection name, entry Dn, attribute description and value and * restores the {@link IValue} object. */ public Object nativeToJava( TransferData transferData ) { try { if ( isSupportedType( transferData ) ) { byte[] buffer = ( byte[] ) super.nativeToJava( transferData ); if ( buffer == null ) { return null; } List<IValue> valueList = new ArrayList<IValue>(); try { ByteArrayInputStream in = new ByteArrayInputStream( buffer ); DataInputStream readIn = new DataInputStream( in ); do { IBrowserConnection connection = null; if ( readIn.available() > 1 ) { int size = readIn.readInt(); byte[] connectionId = new byte[size]; readIn.read( connectionId ); connection = BrowserCorePlugin.getDefault().getConnectionManager() .getBrowserConnectionById( new String( connectionId, "UTF-8" ) ); //$NON-NLS-1$ } IEntry entry = null; if ( readIn.available() > 1 && connection != null ) { int size = readIn.readInt(); byte[] dn = new byte[size]; readIn.read( dn ); entry = connection.getEntryFromCache( new Dn( new String( dn, "UTF-8" ) ) ); //$NON-NLS-1$ } else { return null; } IAttribute attribute = null; if ( readIn.available() > 1 && entry != null ) { int size = readIn.readInt(); byte[] attributeName = new byte[size]; readIn.read( attributeName ); attribute = entry.getAttribute( new String( attributeName, "UTF-8" ) ); //$NON-NLS-1$ } else { return null; } IValue value = null; if ( readIn.available() > 1 && attribute != null ) { boolean isString = readIn.readBoolean(); int size = readIn.readInt(); byte[] val = new byte[size]; readIn.read( val ); String test = new String( val, "UTF-8" ); //$NON-NLS-1$ IValue[] values = attribute.getValues(); for ( int i = 0; i < values.length; i++ ) { if ( isString && values[i].isString() && test.equals( values[i].getStringValue() ) ) { value = values[i]; break; } else if ( !isString && values[i].isBinary() && test.equals( new String( values[i].getBinaryValue(), "UTF-8" ) ) ) //$NON-NLS-1$ { value = values[i]; break; } } } else { return null; } if ( value != null ) { valueList.add( value ); } } while ( readIn.available() > 1 ); readIn.close(); } catch ( IOException ex ) { return null; } return valueList.isEmpty() ? null : valueList.toArray( new IValue[valueList.size()] ); } } catch ( Exception e ) { e.printStackTrace(); } return null; } /** * {@inheritDoc} */ protected String[] getTypeNames() { return new String[] { TYPENAME }; } /** * {@inheritDoc} */ protected int[] getTypeIds() { return new int[] { TYPEID }; } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/actions/FetchReferralsAction.java
plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/actions/FetchReferralsAction.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.ldapbrowser.common.actions; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import org.apache.directory.studio.ldapbrowser.core.jobs.InitializeChildrenRunnable; import org.apache.directory.studio.ldapbrowser.core.jobs.StudioBrowserJob; import org.apache.directory.studio.ldapbrowser.core.model.IEntry; import org.eclipse.jface.action.Action; import org.eclipse.jface.resource.ImageDescriptor; /** * This Action toggles weather to fetch referrals for an entry or not. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class FetchReferralsAction extends BrowserAction { /** * Creates a new instance of FetchReferralsAction. */ public FetchReferralsAction() { } @Override public int getStyle() { return Action.AS_CHECK_BOX; } @Override public String getText() { return Messages.getString( "FetchOperationalAttributesAction.FetchReferrals" ); //$NON-NLS-1$ } @Override public ImageDescriptor getImageDescriptor() { return null; } @Override public String getCommandId() { return null; } @Override public boolean isEnabled() { List<IEntry> entries = getEntries(); return !entries.isEmpty() && !entries.iterator().next().getBrowserConnection().isManageDsaIT(); } @Override public boolean isChecked() { boolean checked = true; List<IEntry> entries = getEntries(); if ( entries.isEmpty() ) { checked = false; } else { for ( IEntry entry : entries ) { if ( !entry.isFetchReferrals() ) { checked = false; } } } return checked; } @Override public void run() { IEntry[] entries = getEntries().toArray( new IEntry[0] ); boolean init = !isChecked(); for ( IEntry entry : entries ) { entry.setFetchReferrals( init ); } new StudioBrowserJob( new InitializeChildrenRunnable( true, entries ) ).execute(); } /** * Gets the Entries * * @return * the entries */ protected List<IEntry> getEntries() { List<IEntry> entriesList = new ArrayList<IEntry>(); entriesList.addAll( Arrays.asList( getSelectedEntries() ) ); return entriesList; } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/actions/PasteAction.java
plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/actions/PasteAction.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.ldapbrowser.common.actions; import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.ui.ISharedImages; import org.eclipse.ui.PlatformUI; import org.eclipse.ui.texteditor.IWorkbenchActionDefinitionIds; /** * This class implements the Paste Action. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public abstract class PasteAction extends BrowserAction { /** * Creates a new instance of PasteAction. */ public PasteAction() { super(); } /** * {@inheritDoc} */ public ImageDescriptor getImageDescriptor() { return PlatformUI.getWorkbench().getSharedImages().getImageDescriptor( ISharedImages.IMG_TOOL_PASTE ); } /** * {@inheritDoc} */ public String getCommandId() { return IWorkbenchActionDefinitionIds.PASTE; } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/actions/NewAttributeAction.java
plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/actions/NewAttributeAction.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.ldapbrowser.common.actions; import org.apache.directory.studio.ldapbrowser.common.BrowserCommonActivator; import org.apache.directory.studio.ldapbrowser.common.BrowserCommonConstants; import org.apache.directory.studio.ldapbrowser.common.wizards.AttributeWizard; import org.apache.directory.studio.ldapbrowser.core.model.IAttribute; import org.apache.directory.studio.ldapbrowser.core.model.IEntry; import org.apache.directory.studio.ldapbrowser.core.model.impl.Attribute; import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.jface.wizard.WizardDialog; /** * This Action creates a new Attribute * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class NewAttributeAction extends BrowserAction { /** * Creates a new instance of NewAttributeAction. */ public NewAttributeAction() { super(); } /** * {@inheritDoc} */ public void dispose() { super.dispose(); } /** * {@inheritDoc} */ public void run() { IEntry entry = null; if ( getInput() instanceof IEntry ) { entry = ( IEntry ) getInput(); } else if ( getSelectedEntries().length > 0 ) { entry = getSelectedEntries()[0]; } else if ( getSelectedAttributes().length > 0 ) { entry = getSelectedAttributes()[0].getEntry(); } else if ( getSelectedValues().length > 0 ) { entry = getSelectedValues()[0].getAttribute().getEntry(); } if ( entry != null ) { AttributeWizard wizard = new AttributeWizard( Messages.getString( "NewAttributeAction.NewAttribute" ), true, true, null, entry ); //$NON-NLS-1$ WizardDialog dialog = new WizardDialog( getShell(), wizard ); dialog.setBlockOnOpen( true ); dialog.create(); if ( dialog.open() == WizardDialog.OK ) { String newAttributeDescription = wizard.getAttributeDescription(); if ( newAttributeDescription != null && !"".equals( newAttributeDescription ) ) //$NON-NLS-1$ { IAttribute att = entry.getAttribute( newAttributeDescription ); if ( att == null ) { att = new Attribute( entry, newAttributeDescription ); entry.addAttribute( att ); } att.addEmptyValue(); } } } } /** * {@inheritDoc} */ public String getText() { return Messages.getString( "NewAttributeAction.NewAttributeLabel" ); //$NON-NLS-1$ } /** * {@inheritDoc} */ public ImageDescriptor getImageDescriptor() { return BrowserCommonActivator.getDefault().getImageDescriptor( BrowserCommonConstants.IMG_ATTRIBUTE_ADD ); } /** * {@inheritDoc} */ public String getCommandId() { return BrowserCommonConstants.CMD_ADD_ATTRIBUTE; } /** * {@inheritDoc} */ public boolean isEnabled() { if ( ( getSelectedSearchResults().length == 1 && getSelectedAttributes().length > 0 ) ) { return false; } return ( ( getInput() instanceof IEntry ) || getSelectedEntries().length == 1 || getSelectedAttributes().length > 0 || getSelectedValues().length > 0 ); } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false