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/edirectory/src/main/java/org/apache/directory/studio/edirectory/Messages.java
plugins/edirectory/src/main/java/org/apache/directory/studio/edirectory/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.edirectory; 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/edirectory/src/main/java/org/apache/directory/studio/edirectory/EDirectoryActivator.java
plugins/edirectory/src/main/java/org/apache/directory/studio/edirectory/EDirectoryActivator.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.edirectory; import java.io.IOException; import java.net.URL; 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.swt.graphics.Image; import org.eclipse.ui.plugin.AbstractUIPlugin; import org.osgi.framework.BundleContext; /** * The activator class controls the plug-in life cycle */ public class EDirectoryActivator extends AbstractUIPlugin { /** The shared instance */ private static EDirectoryActivator plugin; /** The plugin properties */ private PropertyResourceBundle properties; public EDirectoryActivator() { plugin = this; } public void start( BundleContext context ) throws Exception { super.start( context ); } public void stop( BundleContext context ) throws Exception { plugin = null; super.stop( context ); } /** * Returns the shared instance * * @return the shared instance */ public static EDirectoryActivator getDefault() { return plugin; } /** * Use this method to get SWT images. Use the IMG_ constants from * ValueEditorConstants for the key. * * @param key The key (relative path to the image in filesystem) * @return The image descriptor 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 * ValueEditorConstants 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 in filesystem) * @return The SWT Image or null * @see ValueEditorsConstants */ 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; } /** * 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.edirectory", Status.OK, //$NON-NLS-1$ Messages.getString( "EDirectoryActivator.UnableGetPluginProperties" ), 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/aciitemeditor/src/main/java/org/apache/directory/studio/aciitemeditor/ACIITemConstants.java
plugins/aciitemeditor/src/main/java/org/apache/directory/studio/aciitemeditor/ACIITemConstants.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.aciitemeditor; /** * This interface is used to store all constants related to the ACI Item Editor Plugin * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public interface ACIITemConstants { /** The plug-in ID */ String PLUGIN_ID = ACIITemConstants.class.getPackage().getName(); /** The ID for ACI Item Template */ String ACI_ITEM_TEMPLATE_ID = PLUGIN_ID + ".templates"; //$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/aciitemeditor/src/main/java/org/apache/directory/studio/aciitemeditor/package-info.java
plugins/aciitemeditor/src/main/java/org/apache/directory/studio/aciitemeditor/package-info.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. * */ /** * Contains the ACI item editor's * {@link org.apache.directory.studio.valueeditors.IValueEditor} * implementation and the plugin activator. */ package org.apache.directory.studio.aciitemeditor;
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/aciitemeditor/src/main/java/org/apache/directory/studio/aciitemeditor/ACIItemValueWithContext.java
plugins/aciitemeditor/src/main/java/org/apache/directory/studio/aciitemeditor/ACIItemValueWithContext.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.aciitemeditor; import org.apache.directory.studio.ldapbrowser.core.model.IBrowserConnection; import org.apache.directory.studio.ldapbrowser.core.model.IEntry; /** * The ACIItemValueContext is used to pass contextual * information to the opened ACIItemDialog. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class ACIItemValueWithContext { /** The connection, used to browse the directory. */ private IBrowserConnection connection; /** The entry. */ private IEntry entry; /** The ACI item. */ private String aciItemValue; /** * Creates a new instance of ACIItemValueContext. * * @param aciItemValue the ACI item value * @param connection the connection * @param entry the entry */ public ACIItemValueWithContext( IBrowserConnection connection, IEntry entry, String aciItemValue ) { this.connection = connection; this.entry = entry; this.aciItemValue = aciItemValue; } /** * Gets the aci item value. * * @return the aciItemValue */ public String getACIItemValue() { return aciItemValue; } /** * @return the connection */ public IBrowserConnection getConnection() { return connection; } /** * @return the entry */ public IEntry getEntry() { return entry; } /** * {@inheritDoc} */ public String toString() { return aciItemValue == null ? "" : aciItemValue; //$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/aciitemeditor/src/main/java/org/apache/directory/studio/aciitemeditor/Activator.java
plugins/aciitemeditor/src/main/java/org/apache/directory/studio/aciitemeditor/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.aciitemeditor; import java.io.IOException; import java.util.PropertyResourceBundle; import org.apache.directory.api.ldap.aci.ACIItemParser; import org.apache.directory.studio.aciitemeditor.sourceeditor.ACICodeScanner; import org.apache.directory.studio.aciitemeditor.sourceeditor.ACITextAttributeProvider; import org.eclipse.core.runtime.FileLocator; import org.eclipse.core.runtime.Path; import org.eclipse.core.runtime.Status; import org.eclipse.jface.dialogs.Dialog; import org.eclipse.jface.dialogs.IDialogConstants; import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.jface.resource.JFaceResources; import org.eclipse.jface.text.templates.GlobalTemplateVariables; import org.eclipse.swt.graphics.FontMetrics; import org.eclipse.swt.graphics.GC; import org.eclipse.swt.graphics.Image; import org.eclipse.swt.widgets.Control; 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 * * @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 shared ACI Item parser */ private ACIItemParser aciItemParser; /** The shared ACI Code Scanner */ private ACICodeScanner aciCodeScanner; /** The shared ACI TextAttribute Provider */ private ACITextAttributeProvider textAttributeProvider; /** The template store */ private ContributionTemplateStore aciTemplateStore; /** The context type registry */ private ContributionContextTypeRegistry aciTemplateContextTypeRegistry; /** The plugin properties */ private PropertyResourceBundle properties; /** * The constructor */ public Activator() { plugin = this; } /** * {@inheritDoc} */ public void start( BundleContext context ) throws Exception { super.start( context ); // ACI Template ContextType Registry initialization if ( aciTemplateContextTypeRegistry == null ) { aciTemplateContextTypeRegistry = new ContributionContextTypeRegistry(); aciTemplateContextTypeRegistry.addContextType( ACIITemConstants.ACI_ITEM_TEMPLATE_ID ); aciTemplateContextTypeRegistry.getContextType( ACIITemConstants.ACI_ITEM_TEMPLATE_ID ).addResolver( new GlobalTemplateVariables.Cursor() ); } // ACI Template Store initialization if ( aciTemplateStore == null ) { aciTemplateStore = new ContributionTemplateStore( getAciTemplateContextTypeRegistry(), getPreferenceStore(), "templates" ); //$NON-NLS-1$ try { aciTemplateStore.load(); } catch ( IOException e ) { e.printStackTrace(); } } } /** * {@inheritDoc} */ 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 imageDescriptorFromPlugin( ACIITemConstants.PLUGIN_ID, path ); } /** * Use this method to get SWT images. A ImageRegistry is used * to manage the the path->Image mapping. * <p> * Note: Don't dispose the returned SWT Image. It is disposed * automatically when the plugin is stopped. * * @param path the path * @return The SWT Image or null */ public Image getImage( String path ) { Image image = getImageRegistry().get( path ); if ( image == null ) { ImageDescriptor id = getImageDescriptor( path ); if ( id != null ) { image = id.createImage(); getImageRegistry().put( path, image ); } } return image; } /** * Returns the shared ACI item parser. Take care that * the parser isn't used concurrently. * * @return the shared ACI item parser. */ public ACIItemParser getACIItemParser() { if ( aciItemParser == null ) { aciItemParser = new ACIItemParser( null ); } return aciItemParser; } /** * Returns the button with respect to the font metrics. * * @param control a control * @return the button width */ public static int getButtonWidth( Control control ) { GC gc = new GC( control ); try { gc.setFont( JFaceResources.getDialogFont() ); FontMetrics fontMetrics = gc.getFontMetrics(); int width = Dialog.convertHorizontalDLUsToPixels( fontMetrics, IDialogConstants.BUTTON_WIDTH ); return width; } finally { gc.dispose(); } } /** * Returns the TextAttribute Provider * * @return the TextAttribute Provider */ public ACITextAttributeProvider getTextAttributeProvider() { if ( textAttributeProvider == null ) { textAttributeProvider = new ACITextAttributeProvider(); } return textAttributeProvider; } /** * Retuns the the Aci Code Scanner * * @return the the Aci Code Scanner */ public ACICodeScanner getAciCodeScanner() { if ( aciCodeScanner == null ) { aciCodeScanner = new ACICodeScanner( getTextAttributeProvider() ); } return aciCodeScanner; } /** * Gets the ACI Template ContextType Registry * * @return the ACI Template ContextType Registry */ public ContributionContextTypeRegistry getAciTemplateContextTypeRegistry() { return aciTemplateContextTypeRegistry; } /** * Gets the ACI Template Store * * @return the ACI Template Store */ public ContributionTemplateStore getAciTemplateStore() { return aciTemplateStore; } /** * 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.aciitemeditor", 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/aciitemeditor/src/main/java/org/apache/directory/studio/aciitemeditor/ACIItemValueEditor.java
plugins/aciitemeditor/src/main/java/org/apache/directory/studio/aciitemeditor/ACIItemValueEditor.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.aciitemeditor; import org.apache.directory.studio.aciitemeditor.dialogs.ACIItemDialog; import org.apache.directory.studio.ldapbrowser.core.model.AttributeHierarchy; 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.apache.directory.studio.valueeditors.AbstractDialogStringValueEditor; import org.eclipse.swt.widgets.Shell; /** * The IValueEditor implementation of this plugin. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class ACIItemValueEditor extends AbstractDialogStringValueEditor { /** * Opens the ACI item dialog. * * @param shell the shell * * @return true, if open dialog */ public boolean openDialog( Shell shell ) { Object value = getValue(); if ( value instanceof ACIItemValueWithContext ) { ACIItemValueWithContext context = ( ACIItemValueWithContext ) value; ACIItemDialog dialog = new ACIItemDialog( shell, context ); if ( ( dialog.open() == ACIItemDialog.OK ) && !EMPTY.equals( dialog.getACIItemValue() ) ) //$NON-NLS-1$ { setValue( dialog.getACIItemValue() ); return true; } } return false; } /** * Returns a ACIItemValueContext with the connection * and entry of the attribute hierarchy and an empty value if there * are no values in attributeHierarchy. * * Returns a ACIItemValueContext with the connection * and entry of the attribute hierarchy and a value if there is * one value in attributeHierarchy. * * @param attributeHierarchy the attribute hierarchy * * @return the raw value */ public Object getRawValue( AttributeHierarchy attributeHierarchy ) { if ( ( attributeHierarchy != null ) && ( attributeHierarchy.size() == 1 ) ) { if ( attributeHierarchy.getAttribute().getValueSize() == 0 ) { IEntry entry = attributeHierarchy.getAttribute().getEntry(); IBrowserConnection connection = entry.getBrowserConnection(); return new ACIItemValueWithContext( connection, entry, EMPTY ); //$NON-NLS-1$ } else if ( attributeHierarchy.getAttribute().getValueSize() == 1 ) { IEntry entry = attributeHierarchy.getAttribute().getEntry(); IBrowserConnection connection = entry.getBrowserConnection(); String value = getDisplayValue( attributeHierarchy ); return new ACIItemValueWithContext( connection, entry, value ); } } return null; } /** * Returns a ACIItemValueContext with the connection, * entry and string value of the given value. * * @param value the value * * @return the raw value */ public Object getRawValue( IValue value ) { Object object = super.getRawValue( value ); if ( object instanceof String ) { IEntry entry = value.getAttribute().getEntry(); IBrowserConnection connection = entry.getBrowserConnection(); String valueStr = ( String ) object; return new ACIItemValueWithContext( connection, entry, valueStr ); } 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/aciitemeditor/src/main/java/org/apache/directory/studio/aciitemeditor/sourceeditor/package-info.java
plugins/aciitemeditor/src/main/java/org/apache/directory/studio/aciitemeditor/sourceeditor/package-info.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. * */ /** * Contains the source editor configuration. */ package org.apache.directory.studio.aciitemeditor.sourceeditor;
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/aciitemeditor/src/main/java/org/apache/directory/studio/aciitemeditor/sourceeditor/DialogContentAssistant.java
plugins/aciitemeditor/src/main/java/org/apache/directory/studio/aciitemeditor/sourceeditor/DialogContentAssistant.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.aciitemeditor.sourceeditor; import org.eclipse.core.commands.ExecutionEvent; import org.eclipse.core.commands.IHandler; import org.eclipse.jface.contentassist.ComboContentAssistSubjectAdapter; import org.eclipse.jface.contentassist.SubjectControlContentAssistant; import org.eclipse.jface.contentassist.TextContentAssistSubjectAdapter; import org.eclipse.jface.text.ITextViewer; import org.eclipse.swt.events.FocusEvent; import org.eclipse.swt.events.FocusListener; import org.eclipse.swt.events.TraverseEvent; import org.eclipse.swt.events.TraverseListener; import org.eclipse.swt.graphics.Point; import org.eclipse.swt.widgets.Combo; import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Text; import org.eclipse.ui.PlatformUI; import org.eclipse.ui.handlers.IHandlerActivation; import org.eclipse.ui.handlers.IHandlerService; import org.eclipse.ui.texteditor.ITextEditorActionDefinitionIds; /** * This class implements the Content Assistant Dialog used in the ACI Item * Source Editor for displaying proposals * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class DialogContentAssistant extends SubjectControlContentAssistant implements FocusListener { private Control control; private IHandlerActivation handlerActivation; private boolean possibleCompletionsVisible; /** * Creates a new instance of DialogContentAssistant. */ public DialogContentAssistant() { super(); this.possibleCompletionsVisible = false; } /** * Installs content assist support on the given subject. * * @param text * the one who requests content assist */ public void install( Text text ) { this.control = text; this.control.addFocusListener( this ); super.install( new TextContentAssistSubjectAdapter( text ) ); } /** * Installs content assist support on the given subject. * * @param combo * the one who requests content assist */ public void install( Combo combo ) { this.control = combo; this.control.addFocusListener( this ); super.install( new ComboContentAssistSubjectAdapter( combo ) ); } /** * {@inheritDoc} */ public void install( ITextViewer viewer ) { this.control = viewer.getTextWidget(); this.control.addFocusListener( this ); // stop traversal (ESC) if popup is shown this.control.addTraverseListener( new TraverseListener() { public void keyTraversed( TraverseEvent e ) { if ( possibleCompletionsVisible ) { e.doit = false; } } } ); super.install( viewer ); } /** * {@inheritDoc} */ public void uninstall() { if ( this.handlerActivation != null ) { IHandlerService handlerService = ( IHandlerService ) PlatformUI.getWorkbench().getAdapter( IHandlerService.class ); handlerService.deactivateHandler( this.handlerActivation ); this.handlerActivation = null; } if ( this.control != null ) { this.control.removeFocusListener( this ); } super.uninstall(); } /** * {@inheritDoc} */ protected Point restoreCompletionProposalPopupSize() { possibleCompletionsVisible = true; return super.restoreCompletionProposalPopupSize(); } /** * {@inheritDoc} */ public String showPossibleCompletions() { possibleCompletionsVisible = true; return super.showPossibleCompletions(); } /** * {@inheritDoc} */ protected void possibleCompletionsClosed() { this.possibleCompletionsVisible = false; super.possibleCompletionsClosed(); } /** * {@inheritDoc} */ public void focusGained( FocusEvent e ) { IHandlerService handlerService = ( IHandlerService ) PlatformUI.getWorkbench().getAdapter( IHandlerService.class ); if ( handlerService != null ) { IHandler handler = new org.eclipse.core.commands.AbstractHandler() { public Object execute( ExecutionEvent event ) throws org.eclipse.core.commands.ExecutionException { showPossibleCompletions(); return null; } }; this.handlerActivation = handlerService.activateHandler( ITextEditorActionDefinitionIds.CONTENT_ASSIST_PROPOSALS, handler ); } } /** * {@inheritDoc} */ public void focusLost( FocusEvent e ) { if ( this.handlerActivation != null ) { IHandlerService handlerService = ( IHandlerService ) PlatformUI.getWorkbench().getAdapter( IHandlerService.class ); handlerService.deactivateHandler( this.handlerActivation ); this.handlerActivation = 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/aciitemeditor/src/main/java/org/apache/directory/studio/aciitemeditor/sourceeditor/ACISourceViewerConfiguration.java
plugins/aciitemeditor/src/main/java/org/apache/directory/studio/aciitemeditor/sourceeditor/ACISourceViewerConfiguration.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.aciitemeditor.sourceeditor; import org.apache.directory.studio.aciitemeditor.Activator; import org.eclipse.jface.text.IDocument; import org.eclipse.jface.text.contentassist.ContentAssistant; import org.eclipse.jface.text.contentassist.IContentAssistProcessor; import org.eclipse.jface.text.contentassist.IContentAssistant; import org.eclipse.jface.text.formatter.ContentFormatter; import org.eclipse.jface.text.formatter.IContentFormatter; import org.eclipse.jface.text.formatter.IFormattingStrategy; 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 enables the features of the editor (Syntax coloring, code completion, etc.) * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class ACISourceViewerConfiguration 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().getAciCodeScanner() ); reconciler.setDamager( dr, IDocument.DEFAULT_CONTENT_TYPE ); reconciler.setRepairer( dr, IDocument.DEFAULT_CONTENT_TYPE ); return reconciler; } /** * {@inheritDoc} */ public IContentAssistant getContentAssistant( ISourceViewer sourceViewer ) { // ContentAssistant assistant = new ContentAssistant(); ContentAssistant assistant = new DialogContentAssistant(); IContentAssistProcessor aciContentAssistProcessor = new ACIContentAssistProcessor(); assistant.setContentAssistProcessor( aciContentAssistProcessor, IDocument.DEFAULT_CONTENT_TYPE ); assistant.enableAutoActivation( true ); assistant.setAutoActivationDelay( 500 ); assistant.setProposalPopupOrientation( IContentAssistant.PROPOSAL_STACKED ); assistant.setContextInformationPopupOrientation( IContentAssistant.CONTEXT_INFO_ABOVE ); return assistant; } /** * {@inheritDoc} */ public IContentFormatter getContentFormatter( ISourceViewer sourceViewer ) { ContentFormatter formatter = new ContentFormatter(); IFormattingStrategy formattingStrategy = new ACIFormattingStrategy( sourceViewer ); formatter.enablePartitionAwareFormatting( false ); formatter.setFormattingStrategy( formattingStrategy, IDocument.DEFAULT_CONTENT_TYPE ); return formatter; } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/aciitemeditor/src/main/java/org/apache/directory/studio/aciitemeditor/sourceeditor/ACITextAttributeProvider.java
plugins/aciitemeditor/src/main/java/org/apache/directory/studio/aciitemeditor/sourceeditor/ACITextAttributeProvider.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.aciitemeditor.sourceeditor; 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 ACITextAttributeProvider { public static final String DEFAULT_ATTRIBUTE = "__pos_aci_default_attribute"; //$NON-NLS-1$ public static final String KEYWORD_ATTRIBUTE = "__pos_aci_keyword_attribute"; //$NON-NLS-1$ public static final String STRING_ATTRIBUTE = "__pos_aci_string_attribute"; //$NON-NLS-1$ public static final String IDENTIFICATION_ATTRIBUTE = "__pos_aci_identification_attribute"; //$NON-NLS-1$ public static final String PRECEDENCE_ATTRIBUTE = "__pos_aci_precedence_attribute"; //$NON-NLS-1$ public static final String AUTHENTICATIONLEVEL_ATTRIBUTE = "__pos_aci_authenticationlevel_attribute"; //$NON-NLS-1$ public static final String ITEMORUSERFIRST_ATTRIBUTE = "__pos_aci_itemoruserfirst_attribute"; //$NON-NLS-1$ public static final String USER_ATTRIBUTE = "__pos_aci_user_attribute"; //$NON-NLS-1$ public static final String GRANT_VALUE = "__pos_aci_grant_value"; //$NON-NLS-1$ public static final String DENY_VALUE = "__pos_aci_deny_value"; //$NON-NLS-1$ private Map<String, TextAttribute> attributes = new HashMap<String, TextAttribute>(); /** * Creates a new instance of AciTextAttributeProvider. */ public ACITextAttributeProvider() { CommonUIPlugin plugin = CommonUIPlugin.getDefault(); attributes.put( DEFAULT_ATTRIBUTE, new TextAttribute( plugin.getColor( CommonUIConstants.DEFAULT_COLOR ) ) ); attributes.put( KEYWORD_ATTRIBUTE, new TextAttribute( plugin.getColor( CommonUIConstants.ATTRIBUTE_TYPE_COLOR ), null, SWT.BOLD ) ); attributes.put( STRING_ATTRIBUTE, new TextAttribute( plugin.getColor( CommonUIConstants.VALUE_COLOR ) ) ); attributes.put( GRANT_VALUE, new TextAttribute( plugin.getColor( CommonUIConstants.ADD_COLOR ) ) ); attributes.put( DENY_VALUE, new TextAttribute( plugin.getColor( CommonUIConstants.DELETE_COLOR ) ) ); attributes.put( IDENTIFICATION_ATTRIBUTE, new TextAttribute( plugin.getColor( CommonUIConstants.KEYWORD_1_COLOR ), null, SWT.BOLD ) ); attributes.put( PRECEDENCE_ATTRIBUTE, new TextAttribute( plugin.getColor( CommonUIConstants.KEYWORD_1_COLOR ), null, SWT.BOLD ) ); attributes.put( AUTHENTICATIONLEVEL_ATTRIBUTE, new TextAttribute( plugin.getColor( CommonUIConstants.KEYWORD_1_COLOR ), null, SWT.BOLD ) ); attributes.put( ITEMORUSERFIRST_ATTRIBUTE, new TextAttribute( plugin.getColor( CommonUIConstants.KEYWORD_1_COLOR ), null, SWT.BOLD ) ); attributes.put( USER_ATTRIBUTE, new TextAttribute( plugin.getColor( CommonUIConstants.KEYWORD_1_COLOR ), null, SWT.BOLD ) ); } /** * 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/aciitemeditor/src/main/java/org/apache/directory/studio/aciitemeditor/sourceeditor/ACIFormattingStrategy.java
plugins/aciitemeditor/src/main/java/org/apache/directory/studio/aciitemeditor/sourceeditor/ACIFormattingStrategy.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.aciitemeditor.sourceeditor; import org.apache.directory.studio.ldapbrowser.core.BrowserCoreConstants; import org.eclipse.jface.text.formatter.IFormattingStrategy; import org.eclipse.jface.text.source.ISourceViewer; /** * This class implements the formatting strategy for the ACI Item Editor. * <ul> * <li>New line after a comma * <li>New line after a opened left curly * </ul> * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class ACIFormattingStrategy implements IFormattingStrategy { /** The Constant INDENT_STRING. */ public static final String INDENT_STRING = " "; //$NON-NLS-1$ /** The Constant NEWLINE. */ public static final String NEWLINE = BrowserCoreConstants.LINE_SEPARATOR; /** The source viewer. */ private ISourceViewer sourceViewer; /** * Creates a new instance of ACIFormattingStrategy. * * @param sourceViewer the source viewer */ public ACIFormattingStrategy( ISourceViewer sourceViewer ) { this.sourceViewer = sourceViewer; } /** * {@inheritDoc} */ public String format( String content, boolean isLineStart, String indentation, int[] positions ) { String oldContent = sourceViewer.getDocument().get(); String newContent = internFormat( oldContent ); sourceViewer.getDocument().set( newContent ); return null; } /** * {@inheritDoc} */ public void formatterStarts( String initialIndentation ) { } /** * {@inheritDoc} */ public void formatterStops() { } private String internFormat( String content ) { StringBuilder sb = new StringBuilder(); // flag to track if a new line was started boolean newLineStarted = true; // flag to track if we are within a quoted string boolean inQuotedString = false; // flag to track if the current expression is appended in one-line mode boolean oneLineMode = false; // the current indent int indent = 0; int contentLength = content.length(); for ( int i = 0; i < contentLength; i++ ) { char c = content.charAt( i ); // track quotes if ( c == '"' ) { inQuotedString ^= true; } if ( ( c == '{' ) && !inQuotedString ) { // check one-line mode oneLineMode = checkInOneLine( i, content ); if ( oneLineMode ) { // no new line in one-line mode sb.append( c ); newLineStarted = false; } else { // start a new line, but avoid blank lines if there are multiple opened curlies if ( !newLineStarted ) { sb.append( NEWLINE ); for ( int x = 0; x < indent; x++ ) { sb.append( INDENT_STRING ); } } // append the curly sb.append( c ); // start a new line and increment indent sb.append( NEWLINE ); newLineStarted = true; indent++; for ( int x = 0; x < indent; x++ ) { sb.append( INDENT_STRING ); } } } else if ( ( c == '}' ) && !inQuotedString ) { if ( oneLineMode ) { // no new line in one-line mode sb.append( c ); newLineStarted = false; // closed curly indicates end of one-line mode oneLineMode = false; } else { // decrement indent indent--; // start a new line, but avoid blank lines if there are multiple closed curlies if ( newLineStarted ) { // delete one indent sb.delete( sb.length() - INDENT_STRING.length(), sb.length() ); } else { sb.append( NEWLINE ); for ( int x = 0; x < indent; x++ ) { sb.append( INDENT_STRING ); } } // append the curly sb.append( c ); // start a new line sb.append( NEWLINE ); newLineStarted = true; for ( int x = 0; x < indent; x++ ) { sb.append( INDENT_STRING ); } } } else if ( ( c == ',' ) && !inQuotedString ) { // start new line on comma if ( oneLineMode ) { sb.append( c ); newLineStarted = false; } else { sb.append( c ); sb.append( NEWLINE ); newLineStarted = true; for ( int x = 0; x < indent; x++ ) { sb.append( INDENT_STRING ); } } } else if ( Character.isWhitespace( c ) ) { char c1 = 'A'; if ( i + 1 < contentLength ) { c1 = content.charAt( i + 1 ); } if ( ( !newLineStarted ) && // ignore space after starting a new line ( c != '\n' ) && ( c != '\r' ) && // ignore new lines !Character.isWhitespace( c1 ) && ( c1 != '\n' ) && ( c1 != '\r' ) ) // compress whitespaces { sb.append( c ); } } else { // default case: append the char sb.append( c ); newLineStarted = false; } } return sb.toString(); } /** * Checks if an expression could be appended in one line. That is * if the expression starting at index i doesn't contain nested * expressions and only one comma. * * @param i the starting index of the expression * @param content the content * * @return true, if the expression could be appended in one line */ private boolean checkInOneLine( int i, String content ) { // flag to track if we are within a quoted string boolean inQuote = false; // counter for commas int commaCounter = 0; int contentLength = content.length(); for ( int k = i + 1; k < contentLength; k++ ) { char c = content.charAt( k ); // track quotes if ( c == '"' ) { inQuote ^= true; } // open curly indicates nested expression if ( ( c == '{' ) && !inQuote ) { return false; } // closing curly indicates end of expression if ( c == '}' && !inQuote ) { return true; } // allow only single comma in an expression in one line if ( c == ',' && !inQuote ) { commaCounter++; if ( commaCounter > 1 ) { return false; } } } 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/aciitemeditor/src/main/java/org/apache/directory/studio/aciitemeditor/sourceeditor/ACIContentAssistProcessor.java
plugins/aciitemeditor/src/main/java/org/apache/directory/studio/aciitemeditor/sourceeditor/ACIContentAssistProcessor.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.aciitemeditor.sourceeditor; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import org.apache.directory.studio.aciitemeditor.ACIITemConstants; import org.apache.directory.studio.aciitemeditor.Activator; import org.eclipse.jface.text.IRegion; import org.eclipse.jface.text.ITextViewer; import org.eclipse.jface.text.contentassist.ICompletionProposal; import org.eclipse.jface.text.contentassist.IContextInformation; import org.eclipse.jface.text.contentassist.IContextInformationValidator; import org.eclipse.jface.text.templates.Template; import org.eclipse.jface.text.templates.TemplateCompletionProcessor; import org.eclipse.jface.text.templates.TemplateContextType; import org.eclipse.swt.graphics.Image; /** * This class implements the Content Assist Processor for ACI Item * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class ACIContentAssistProcessor extends TemplateCompletionProcessor { /** * {@inheritDoc} */ public ICompletionProposal[] computeCompletionProposals( ITextViewer viewer, int offset ) { List<ICompletionProposal> proposalList = new ArrayList<ICompletionProposal>(); // Add context dependend template proposals ICompletionProposal[] templateProposals = super.computeCompletionProposals( viewer, offset ); if ( templateProposals != null ) { proposalList.addAll( Arrays.asList( templateProposals ) ); } return ( ICompletionProposal[] ) proposalList.toArray( new ICompletionProposal[proposalList.size()] ); } /** * {@inheritDoc} */ public IContextInformation[] computeContextInformation( ITextViewer viewer, int offset ) { return null; } /** * {@inheritDoc} */ public char[] getCompletionProposalAutoActivationCharacters() { char[] chars = new char[52]; for ( int i = 0; i < 26; i++ ) { chars[i] = ( char ) ( 'a' + i ); } for ( int i = 0; i < 26; i++ ) { chars[i + 26] = ( char ) ( 'A' + i ); } return chars; } /** * {@inheritDoc} */ public char[] getContextInformationAutoActivationCharacters() { return null; } /** * {@inheritDoc} */ public IContextInformationValidator getContextInformationValidator() { return null; } /** * {@inheritDoc} */ public String getErrorMessage() { return null; } /** * {@inheritDoc} */ protected TemplateContextType getContextType( ITextViewer viewer, IRegion region ) { return Activator.getDefault().getAciTemplateContextTypeRegistry().getContextType( ACIITemConstants.ACI_ITEM_TEMPLATE_ID ); } /** * {@inheritDoc} */ protected Image getImage( Template template ) { return null; } /** * {@inheritDoc} */ protected Template[] getTemplates( String contextTypeId ) { return Activator.getDefault().getAciTemplateStore().getTemplates( contextTypeId ); } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/aciitemeditor/src/main/java/org/apache/directory/studio/aciitemeditor/sourceeditor/ACICodeScanner.java
plugins/aciitemeditor/src/main/java/org/apache/directory/studio/aciitemeditor/sourceeditor/ACICodeScanner.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.aciitemeditor.sourceeditor; 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 ACI code. Allows syntax coloring. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class ACICodeScanner extends RuleBasedScanner { /** 'identificationTag' keyword */ public static final String IDENTIFICATION_TAG_PARTITION = "identificationTag"; //$NON-NLS-1$ /** 'precedence' keyword */ public static final String PRECEDENCE_PARTITION = "precedence"; //$NON-NLS-1$ /** 'authenticationLevel' keyword */ public static final String AUTHENTICATION_LEVEL_PARTITION = "authenticationLevel"; //$NON-NLS-1$ /** Keywords for the itemOrUserFirst Section */ public static final String[] ITEM_OR_USER_FIRST_SECTION_PARTITION = new String[] { "itemOrUserFirst", "itemFirst", "userFirst" }; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ /** Keywords for 'userFirst' section */ public static final String[] USER_SECTION = new String[] { "userClasses", "userPermissions" }; //$NON-NLS-1$ //$NON-NLS-2$ /** Keywords for AciItems values */ public static final String[] ACI_KEYWORDS = new String[] { "protectedItems", //$NON-NLS-1$ "itemPermissions", //$NON-NLS-1$ "entry", //$NON-NLS-1$ "allUserAttributeTypes", //$NON-NLS-1$ "attributeType", //$NON-NLS-1$ "allAttributeValues", //$NON-NLS-1$ "allUserAttributeTypesAndValues", //$NON-NLS-1$ "attributeValue", //$NON-NLS-1$ "selfValue", //$NON-NLS-1$ "rangeOfValues", //$NON-NLS-1$ "maxValueCount", //$NON-NLS-1$ "maxImmSub", //$NON-NLS-1$ "restrictedBy", //$NON-NLS-1$ "classes", //$NON-NLS-1$ "grantsAndDenials", //$NON-NLS-1$ "allUsers", //$NON-NLS-1$ "thisEntry", //$NON-NLS-1$ "name", //$NON-NLS-1$ "userGroup", //$NON-NLS-1$ "subtree", //$NON-NLS-1$ "type", //$NON-NLS-1$ "valuesIn", //$NON-NLS-1$ "none", //$NON-NLS-1$ "simple", //$NON-NLS-1$ "strong" }; //$NON-NLS-1$ /** Keywords for grant values */ public static final String[] ACI_GRANT_VALUES = new String[] { "grantAdd", //$NON-NLS-1$ "grantDiscloseOnError", //$NON-NLS-1$ "grantRead", //$NON-NLS-1$ "grantRemove", //$NON-NLS-1$ "grantBrowse", //$NON-NLS-1$ "grantExport", //$NON-NLS-1$ "grantImport", //$NON-NLS-1$ "grantModify", //$NON-NLS-1$ "grantRename", //$NON-NLS-1$ "grantReturnDN", //$NON-NLS-1$ "grantCompare", //$NON-NLS-1$ "grantFilterMatch", //$NON-NLS-1$ "grantInvoke", }; //$NON-NLS-1$ /** Keywords for deny values */ public static final String[] ACI_DENY_VALUES = new String[] { "denyAdd", //$NON-NLS-1$ "denyDiscloseOnError", //$NON-NLS-1$ "denyRead", //$NON-NLS-1$ "denyRemove", //$NON-NLS-1$ "denyBrowse", //$NON-NLS-1$ "denyExport", //$NON-NLS-1$ "denyImport", //$NON-NLS-1$ "denyModify", //$NON-NLS-1$ "denyRename", //$NON-NLS-1$ "denyReturnDN", //$NON-NLS-1$ "denyCompare", //$NON-NLS-1$ "denyFilterMatch", //$NON-NLS-1$ "denyInvoke" }; //$NON-NLS-1$ /** * Creates a new instance of AciCodeScanner. * * @param provider * the provider */ public ACICodeScanner( ACITextAttributeProvider provider ) { List<IRule> rules = new ArrayList<IRule>(); IToken keyword = new Token( provider.getAttribute( ACITextAttributeProvider.KEYWORD_ATTRIBUTE ) ); IToken undefined = new Token( provider.getAttribute( ACITextAttributeProvider.DEFAULT_ATTRIBUTE ) ); IToken string = new Token( provider.getAttribute( ACITextAttributeProvider.STRING_ATTRIBUTE ) ); IToken grantValue = new Token( provider.getAttribute( ACITextAttributeProvider.GRANT_VALUE ) ); IToken denyValue = new Token( provider.getAttribute( ACITextAttributeProvider.DENY_VALUE ) ); IToken identification = new Token( provider.getAttribute( ACITextAttributeProvider.IDENTIFICATION_ATTRIBUTE ) ); IToken precedence = new Token( provider.getAttribute( ACITextAttributeProvider.PRECEDENCE_ATTRIBUTE ) ); IToken authenticationLevel = new Token( provider .getAttribute( ACITextAttributeProvider.AUTHENTICATIONLEVEL_ATTRIBUTE ) ); IToken itemOrUserFirst = new Token( provider.getAttribute( ACITextAttributeProvider.ITEMORUSERFIRST_ATTRIBUTE ) ); IToken user = new Token( provider.getAttribute( ACITextAttributeProvider.USER_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 ); } } ) ); // If the word isn't in the List, returns undefined WordRule worldRule = new WordRule( new AciWordDetector(), undefined ); // Adding Keywords for ( String aciKeyword : ACI_KEYWORDS ) { worldRule.addWord( aciKeyword, keyword ); } // Adding GrantValues for ( String aciGrantValue : ACI_GRANT_VALUES ) { worldRule.addWord( aciGrantValue, grantValue ); } // Adding DenyValues for ( String aciDenyValue : ACI_DENY_VALUES ) { worldRule.addWord( aciDenyValue, denyValue ); } // Adding itemOrUserFirstSectionPartition for ( String itemOrUserFirstSectionPartitionValue : ITEM_OR_USER_FIRST_SECTION_PARTITION ) { worldRule.addWord( itemOrUserFirstSectionPartitionValue, itemOrUserFirst ); } // Adding User for ( String userSectionValue : USER_SECTION ) { worldRule.addWord( userSectionValue, user ); } worldRule.addWord( IDENTIFICATION_TAG_PARTITION, identification ); worldRule.addWord( PRECEDENCE_PARTITION, precedence ); worldRule.addWord( AUTHENTICATION_LEVEL_PARTITION, authenticationLevel ); rules.add( worldRule ); IRule[] param = new IRule[rules.size()]; rules.toArray( param ); setRules( param ); } /** * This class implements a word detector for ACI Items * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ static class AciWordDetector implements IWordDetector { /** * {@inheritDoc} */ public boolean isWordPart( char c ) { return ( Character.isLetterOrDigit( c ) || c == '_' || c == '$' || c == '#' || c == '@' || c == '~' || c == '.' || c == '?' ); } /** * {@inheritDoc} */ public boolean isWordStart( char c ) { return ( Character.isLetter( c ) || c == '.' || c == '_' || c == '?' || 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/aciitemeditor/src/main/java/org/apache/directory/studio/aciitemeditor/model/UserClassWrapper.java
plugins/aciitemeditor/src/main/java/org/apache/directory/studio/aciitemeditor/model/UserClassWrapper.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.aciitemeditor.model; import java.text.ParseException; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; import org.apache.directory.api.ldap.aci.ACIItemParser; import org.apache.directory.api.ldap.aci.UserClass; import org.apache.directory.api.ldap.aci.UserFirstACIItem; import org.apache.directory.api.ldap.model.subtree.SubtreeSpecification; import org.apache.directory.studio.valueeditors.AbstractDialogStringValueEditor; import org.eclipse.osgi.util.NLS; /** * The UserClassWrapper is used as input for the table viewer. * The user class values are always stored as raw string values. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class UserClassWrapper { /** This map contains all possible user class identifiers */ public static final Map<Class<? extends UserClass>, String> CLASS_TO_IDENTIFIER_MAP; static { Map<Class<? extends UserClass>, String> map = new HashMap<>(); map.put( UserClass.AllUsers.class, "allUsers" ); //$NON-NLS-1$ map.put( UserClass.ThisEntry.class, "thisEntry" ); //$NON-NLS-1$ map.put( UserClass.ParentOfEntry.class, "parentOfEntry" ); //$NON-NLS-1$ map.put( UserClass.Name.class, "name" ); //$NON-NLS-1$ map.put( UserClass.UserGroup.class, "userGroup" ); //$NON-NLS-1$ map.put( UserClass.Subtree.class, "subtree" ); //$NON-NLS-1$ CLASS_TO_IDENTIFIER_MAP = Collections.unmodifiableMap( map ); } /** This map contains all user class display values */ public static final Map<Class<? extends UserClass>, String> CLASS_TO_DISPLAY_MAP; static { Map<Class<? extends UserClass>, String> map = new HashMap<>(); map.put( UserClass.AllUsers.class, Messages.getString( "UserClassWrapper.userClass.allUsers.label" ) ); //$NON-NLS-1$ map.put( UserClass.ThisEntry.class, Messages.getString( "UserClassWrapper.userClass.thisEntry.label" ) ); //$NON-NLS-1$ map.put( UserClass.ParentOfEntry.class, Messages.getString( "UserClassWrapper.userClass.parentOfEntry.label" ) ); //$NON-NLS-1$ map.put( UserClass.Name.class, Messages.getString( "UserClassWrapper.userClass.name.label" ) ); //$NON-NLS-1$ map.put( UserClass.UserGroup.class, Messages.getString( "UserClassWrapper.userClass.userGroup.label" ) ); //$NON-NLS-1$ map.put( UserClass.Subtree.class, Messages.getString( "UserClassWrapper.userClass.subtree.label" ) ); //$NON-NLS-1$ CLASS_TO_DISPLAY_MAP = Collections.unmodifiableMap( map ); } /** A dummy ACI to check syntax of the userClassValue. */ private static final String DUMMY = "{ identificationTag \"id1\", precedence 1, authenticationLevel simple, " //$NON-NLS-1$ + "itemOrUserFirst userFirst: { userClasses { #identifier# #values# }, " //$NON-NLS-1$ + "userPermissions { { protectedItems { entry }, grantsAndDenials { grantRead } } } } }"; //$NON-NLS-1$ /** The class of the user class, never null. */ private final Class<? extends UserClass> clazz; /** The user class values, may be empty. */ private final List<String> values; /** The value prefix, prepended to the value. */ private final String valuePrefix; /** The value suffix, appended to the value. */ private final String valueSuffix; /** The value editor, null means no value. */ private final AbstractDialogStringValueEditor valueEditor; /** * Creates a new instance of UserClassWrapper. * * @param clazz the java class of the UserClass * @param valuePrefix the identifier * @param valueSuffix the dislpay name * @param valueEditor the value editor */ public UserClassWrapper( Class<? extends UserClass> clazz, String valuePrefix, String valueSuffix, AbstractDialogStringValueEditor valueEditor ) { this.clazz = clazz; this.valuePrefix = valuePrefix; this.valueSuffix = valueSuffix; this.valueEditor = valueEditor; this.values = new ArrayList<>(); } /** * Creates a new user class object. Therefore it uses the * dummy ACI, injects the user class and its value, parses * the ACI and extracts the user class from the parsed bean. * * @return the parsed user class * * @throws ParseException if parsing fails */ public UserClass getUserClass() throws ParseException { String flatValue = getFlatValue(); String spec = DUMMY; spec = spec.replaceAll( "#identifier#", getIdentifier() ); //$NON-NLS-1$ spec = spec.replaceAll( "#values#", flatValue ); //$NON-NLS-1$ ACIItemParser parser = new ACIItemParser( null ); UserFirstACIItem aci = null; try { aci = ( UserFirstACIItem ) parser.parse( spec ); } catch ( ParseException e ) { String msg = NLS.bind( Messages.getString( "UserClassWrapper.error.message" ), new String[] { getIdentifier(), flatValue } ); //$NON-NLS-1$ throw new ParseException( msg, 0 ); } return aci.getUserClasses().iterator().next(); } /** * Sets the user class. * * @param userClass the user class */ public void setUserClass( UserClass userClass ) { assert userClass.getClass() == getClazz(); // first clear values values.clear(); // switch on userClass type // no value in UserClass.AllUsers and UserClass.ThisEntry if ( userClass.getClass() == UserClass.Name.class ) { UserClass.Name name = ( UserClass.Name ) userClass; for ( String jndiName : name.getNames() ) { values.add( jndiName ); } } else if ( userClass.getClass() == UserClass.UserGroup.class ) { UserClass.UserGroup userGroups = ( UserClass.UserGroup ) userClass; for ( String jndiName : userGroups.getNames() ) { values.add( jndiName ); } } else if ( userClass.getClass() == UserClass.Subtree.class ) { UserClass.Subtree subtree = ( UserClass.Subtree ) userClass; for ( SubtreeSpecification subtreeSpecification : subtree.getSubtreeSpecifications() ) { StringBuilder buffer = new StringBuilder(); subtreeSpecification.toString( buffer ); values.add( buffer.toString() ); } } } /** * Returns a user-friedly string, displayed in the table. * * @return the string */ public String toString() { String flatValue = getFlatValue(); StringBuilder sb = new StringBuilder(); if ( flatValue.length() > 0 ) { flatValue = flatValue.replace( '\r', ' ' ); flatValue = flatValue.replace( '\n', ' ' ); flatValue = ": " + flatValue; //$NON-NLS-1$ if ( flatValue.length() > 40 ) { String temp = flatValue; flatValue = temp.substring( 0, 20 ); flatValue = flatValue + "..."; //$NON-NLS-1$ flatValue = flatValue + temp.substring( temp.length() - 20, temp.length() ); } } return sb.append( getDisplayName() ).append( ' ' ).append( flatValue ).toString(); //$NON-NLS-1$ } /** * Returns the flat value. * * @return the flat value */ private String getFlatValue() { if ( ( valueEditor == null ) || values.isEmpty() ) { return ""; //$NON-NLS-1$ } StringBuilder buffer = new StringBuilder(); buffer.append( "{ " ); //$NON-NLS-1$ boolean isFirst = true; for ( String value : values ) { if ( isFirst ) { isFirst = false; } else { buffer.append( ", " ); //$NON-NLS-1$ } buffer.append( valuePrefix ); buffer.append( value ); buffer.append( valueSuffix ); } buffer.append( " }" ); //$NON-NLS-1$ return buffer.toString(); } /** * Returns the list of values, may be modified. * * @return the modifiable list of values. */ public List<String> getValues() { return values; } /** * Gets the display name. * * @return the display name */ public String getDisplayName() { return CLASS_TO_DISPLAY_MAP.get( clazz ); } /** * Gets the identifier. * * @return the identifier */ public String getIdentifier() { return CLASS_TO_IDENTIFIER_MAP.get( clazz ); } /** * Returns the class of the user class. * * @return the class of the user class. */ public Class<? extends UserClass> getClazz() { return clazz; } /** * Checks if is editable. * * @return true, if is editable */ public boolean isEditable() { return valueEditor != null; } /** * Gets the value editor. * * @return the value editor, may be null. */ public AbstractDialogStringValueEditor getValueEditor() { return valueEditor; } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/aciitemeditor/src/main/java/org/apache/directory/studio/aciitemeditor/model/package-info.java
plugins/aciitemeditor/src/main/java/org/apache/directory/studio/aciitemeditor/model/package-info.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. * */ /** * Contains the model for the ACI item editor. */ package org.apache.directory.studio.aciitemeditor.model;
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/aciitemeditor/src/main/java/org/apache/directory/studio/aciitemeditor/model/UserClassWrapperFactory.java
plugins/aciitemeditor/src/main/java/org/apache/directory/studio/aciitemeditor/model/UserClassWrapperFactory.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.aciitemeditor.model; import org.apache.directory.api.ldap.aci.UserClass; import org.apache.directory.studio.aciitemeditor.valueeditors.SubtreeValueEditor; import org.apache.directory.studio.valueeditors.dn.DnValueEditor; /** * The UserClassWrapperFactory creates the UserClassWrapper, ready to * be used in the user classes table. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public final class UserClassWrapperFactory { /** * Creates the user class wrappers. * * @return the user class wrapper[] */ public static UserClassWrapper[] createUserClassWrappers() { UserClassWrapper[] userClassWrappers = new UserClassWrapper[] { // allUsers new UserClassWrapper( UserClass.AllUsers.class, "", //$NON-NLS-1$ "", //$NON-NLS-1$ null ), // thisEntry new UserClassWrapper( UserClass.ThisEntry.class, "", //$NON-NLS-1$ "", //$NON-NLS-1$ null ), // parentOfEntry new UserClassWrapper( UserClass.ParentOfEntry.class, "", //$NON-NLS-1$ "", //$NON-NLS-1$ null ), // name new UserClassWrapper( UserClass.Name.class, "\"", //$NON-NLS-1$ "\"", //$NON-NLS-1$ new DnValueEditor() ), // userGroup new UserClassWrapper( UserClass.UserGroup.class, "\"", //$NON-NLS-1$ "\"", //$NON-NLS-1$ new DnValueEditor() ), // subtree new UserClassWrapper( UserClass.Subtree.class, "", //$NON-NLS-1$ "", //$NON-NLS-1$ new SubtreeValueEditor( false, false ) ) }; return userClassWrappers; } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/aciitemeditor/src/main/java/org/apache/directory/studio/aciitemeditor/model/Messages.java
plugins/aciitemeditor/src/main/java/org/apache/directory/studio/aciitemeditor/model/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.aciitemeditor.model; 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 final 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/aciitemeditor/src/main/java/org/apache/directory/studio/aciitemeditor/model/ProtectedItemWrapperFactory.java
plugins/aciitemeditor/src/main/java/org/apache/directory/studio/aciitemeditor/model/ProtectedItemWrapperFactory.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.aciitemeditor.model; import org.apache.directory.api.ldap.aci.protectedItem.AllAttributeValuesItem; import org.apache.directory.api.ldap.aci.protectedItem.AllUserAttributeTypesAndValuesItem; import org.apache.directory.api.ldap.aci.protectedItem.AllUserAttributeTypesItem; import org.apache.directory.api.ldap.aci.protectedItem.AttributeTypeItem; import org.apache.directory.api.ldap.aci.protectedItem.AttributeValueItem; import org.apache.directory.api.ldap.aci.protectedItem.ClassesItem; import org.apache.directory.api.ldap.aci.protectedItem.EntryItem; import org.apache.directory.api.ldap.aci.protectedItem.MaxImmSubItem; import org.apache.directory.api.ldap.aci.protectedItem.MaxValueCountItem; import org.apache.directory.api.ldap.aci.protectedItem.RangeOfValuesItem; import org.apache.directory.api.ldap.aci.protectedItem.RestrictedByItem; import org.apache.directory.api.ldap.aci.protectedItem.SelfValueItem; import org.apache.directory.studio.aciitemeditor.valueeditors.AttributeTypeAndValueValueEditor; import org.apache.directory.studio.aciitemeditor.valueeditors.AttributeTypeValueEditor; import org.apache.directory.studio.aciitemeditor.valueeditors.FilterValueEditor; import org.apache.directory.studio.aciitemeditor.valueeditors.MaxValueCountValueEditor; import org.apache.directory.studio.aciitemeditor.valueeditors.RestrictedByValueEditor; import org.apache.directory.studio.valueeditors.TextValueEditor; import org.apache.directory.studio.valueeditors.integer.IntegerValueEditor; /** * The ProtectedItemWrapperFactory creates the ProtectedItemWrappers, ready to * be used in the protected item table. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public final class ProtectedItemWrapperFactory { /** * Creates the protected item wrappers. * * @return the protected item wrapper[] */ public static ProtectedItemWrapper[] createProtectedItemWrappers() { ProtectedItemWrapper[] protectedItemWrappers = new ProtectedItemWrapper[] { // entry new ProtectedItemWrapper( EntryItem.class, false, "", //$NON-NLS-1$ "", //$NON-NLS-1$ null ), // allUserAttributeTypes new ProtectedItemWrapper( AllUserAttributeTypesItem.class, false, "", //$NON-NLS-1$ "", //$NON-NLS-1$ null ), // attributeType { 1.2.3, cn } new ProtectedItemWrapper( AttributeTypeItem.class, true, "", //$NON-NLS-1$ "", //$NON-NLS-1$ new AttributeTypeValueEditor() ), // allAttributeValues { 1.2.3, cn } new ProtectedItemWrapper( AllAttributeValuesItem.class, true, "", //$NON-NLS-1$ "", //$NON-NLS-1$ new AttributeTypeValueEditor() ), // attributeType new ProtectedItemWrapper( AllUserAttributeTypesAndValuesItem.class, false, "", //$NON-NLS-1$ "", //$NON-NLS-1$ null ), // attributeValue { ou=people, cn=Ersin } new ProtectedItemWrapper( AttributeValueItem.class, true, "", //$NON-NLS-1$ "", //$NON-NLS-1$ new AttributeTypeAndValueValueEditor() ), // selfValue { 1.2.3, cn } new ProtectedItemWrapper( SelfValueItem.class, true, "", //$NON-NLS-1$ "", //$NON-NLS-1$ new AttributeTypeValueEditor() ), // rangeOfValues (cn=E*) new ProtectedItemWrapper( RangeOfValuesItem.class, false, "", //$NON-NLS-1$ "", //$NON-NLS-1$ new FilterValueEditor() ), // maxValueCount { { type 10.11.12, maxCount 10 }, { maxCount 20, type 11.12.13 } } new ProtectedItemWrapper( MaxValueCountItem.class, true, "", //$NON-NLS-1$ "", //$NON-NLS-1$ new MaxValueCountValueEditor() ), // maxImmSub 3 new ProtectedItemWrapper( MaxImmSubItem.class, false, "", //$NON-NLS-1$ "", //$NON-NLS-1$ new IntegerValueEditor() ), // restrictedBy { { type 10.11.12, valuesIn ou }, { valuesIn cn, type 11.12.13 } } new ProtectedItemWrapper( RestrictedByItem.class, true, "", //$NON-NLS-1$ "", //$NON-NLS-1$ new RestrictedByValueEditor() ), // classes and : { item: xyz , or:{item:X,item:Y} } new ProtectedItemWrapper( ClassesItem.class, false, "", //$NON-NLS-1$ "", //$NON-NLS-1$ new TextValueEditor() // TODO: RefinementValueEditor ), }; return protectedItemWrappers; } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/aciitemeditor/src/main/java/org/apache/directory/studio/aciitemeditor/model/ProtectedItemWrapper.java
plugins/aciitemeditor/src/main/java/org/apache/directory/studio/aciitemeditor/model/ProtectedItemWrapper.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.aciitemeditor.model; import java.text.ParseException; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; import org.apache.directory.api.ldap.aci.ACIItemParser; import org.apache.directory.api.ldap.aci.ItemFirstACIItem; import org.apache.directory.api.ldap.aci.ProtectedItem; import org.apache.directory.api.ldap.aci.protectedItem.AllAttributeValuesItem; import org.apache.directory.api.ldap.aci.protectedItem.AllUserAttributeTypesAndValuesItem; import org.apache.directory.api.ldap.aci.protectedItem.AllUserAttributeTypesItem; import org.apache.directory.api.ldap.aci.protectedItem.AttributeTypeItem; import org.apache.directory.api.ldap.aci.protectedItem.AttributeValueItem; import org.apache.directory.api.ldap.aci.protectedItem.ClassesItem; import org.apache.directory.api.ldap.aci.protectedItem.EntryItem; import org.apache.directory.api.ldap.aci.protectedItem.MaxImmSubItem; import org.apache.directory.api.ldap.aci.protectedItem.MaxValueCountElem; import org.apache.directory.api.ldap.aci.protectedItem.MaxValueCountItem; import org.apache.directory.api.ldap.aci.protectedItem.RangeOfValuesItem; import org.apache.directory.api.ldap.aci.protectedItem.RestrictedByElem; import org.apache.directory.api.ldap.aci.protectedItem.RestrictedByItem; import org.apache.directory.api.ldap.aci.protectedItem.SelfValueItem; import org.apache.directory.api.ldap.model.entry.Attribute; import org.apache.directory.api.ldap.model.schema.AttributeType; import org.apache.directory.studio.valueeditors.AbstractDialogStringValueEditor; import org.eclipse.osgi.util.NLS; /** * The ProtectedItemWrapper is used as input for the table viewer. * The protected item values are always stored as raw string value. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class ProtectedItemWrapper { /** This map contains all possible protected item identifiers */ public static final Map<Class<? extends ProtectedItem>, String> CLASS_TO_IDENTIFIER_MAP; static { Map<Class<? extends ProtectedItem>, String> map = new HashMap<Class<? extends ProtectedItem>, String>(); map.put( EntryItem.class, "entry" ); //$NON-NLS-1$ map.put( AllUserAttributeTypesItem.class, "allUserAttributeTypes" ); //$NON-NLS-1$ map.put( AttributeTypeItem.class, "attributeType" ); //$NON-NLS-1$ map.put( AllAttributeValuesItem.class, "allAttributeValues" ); //$NON-NLS-1$ map.put( AllUserAttributeTypesAndValuesItem.class, "allUserAttributeTypesAndValues" ); //$NON-NLS-1$ map.put( AttributeValueItem.class, "attributeValue" ); //$NON-NLS-1$ map.put( SelfValueItem.class, "selfValue" ); //$NON-NLS-1$ map.put( RangeOfValuesItem.class, "rangeOfValues" ); //$NON-NLS-1$ map.put( MaxValueCountItem.class, "maxValueCount" ); //$NON-NLS-1$ map.put( MaxImmSubItem.class, "maxImmSub" ); //$NON-NLS-1$ map.put( RestrictedByItem.class, "restrictedBy" ); //$NON-NLS-1$ map.put( ClassesItem.class, "classes" ); //$NON-NLS-1$ CLASS_TO_IDENTIFIER_MAP = Collections.unmodifiableMap( map ); } /** This map contains all protected item display values */ public static final Map<Class<? extends ProtectedItem>, String> CLASS_TO_DISPLAY_MAP; static { Map<Class<? extends ProtectedItem>, String> map = new HashMap<Class<? extends ProtectedItem>, String>(); map.put( EntryItem.class, Messages.getString( "ProtectedItemWrapper.protectedItem.entry.label" ) ); //$NON-NLS-1$ map.put( AllUserAttributeTypesItem.class, Messages .getString( "ProtectedItemWrapper.protectedItem.allUserAttributeTypes.label" ) ); //$NON-NLS-1$ map.put( AttributeTypeItem.class, Messages .getString( "ProtectedItemWrapper.protectedItem.attributeType.label" ) ); //$NON-NLS-1$ map.put( AllAttributeValuesItem.class, Messages .getString( "ProtectedItemWrapper.protectedItem.allAttributeValues.label" ) ); //$NON-NLS-1$ map.put( AllUserAttributeTypesAndValuesItem.class, Messages .getString( "ProtectedItemWrapper.protectedItem.allUserAttributeTypesAndValues.label" ) ); //$NON-NLS-1$ map.put( AttributeValueItem.class, Messages .getString( "ProtectedItemWrapper.protectedItem.attributeValue.label" ) ); //$NON-NLS-1$ map.put( SelfValueItem.class, Messages .getString( "ProtectedItemWrapper.protectedItem.selfValue.label" ) ); //$NON-NLS-1$ map.put( RangeOfValuesItem.class, Messages .getString( "ProtectedItemWrapper.protectedItem.rangeOfValues.label" ) ); //$NON-NLS-1$ map.put( MaxValueCountItem.class, Messages .getString( "ProtectedItemWrapper.protectedItem.maxValueCount.label" ) ); //$NON-NLS-1$ map.put( MaxImmSubItem.class, Messages .getString( "ProtectedItemWrapper.protectedItem.maxImmSub.label" ) ); //$NON-NLS-1$ map.put( RestrictedByItem.class, Messages .getString( "ProtectedItemWrapper.protectedItem.restrictedBy.label" ) ); //$NON-NLS-1$ map.put( ClassesItem.class, Messages.getString( "ProtectedItemWrapper.protectedItem.classes.label" ) ); //$NON-NLS-1$ CLASS_TO_DISPLAY_MAP = Collections.unmodifiableMap( map ); } /** A dummy ACI to check syntax of the protectedItemValue */ private static final String DUMMY = "{ identificationTag \"id1\", precedence 1, authenticationLevel simple, " //$NON-NLS-1$ + "itemOrUserFirst itemFirst: { protectedItems { #identifier# #values# }, " //$NON-NLS-1$ + "itemPermissions { { userClasses { allUsers }, grantsAndDenials { grantRead } } } } }"; //$NON-NLS-1$ /** The class of the protected item, never null. */ private final Class<? extends ProtectedItem> clazz; /** The protected item values, may be empty. */ private List<String> values; /** The value prefix, prepended to the value. */ private final String valuePrefix; /** The value suffix, appended to the value. */ private final String valueSuffix; /** The value editor, null means no value. */ private AbstractDialogStringValueEditor valueEditor; /** The multivalued. */ private final boolean multivalued; /** * Creates a new instance of ProtectedItemWrapper. * * @param clazz the java class of the UserClass * @param multivalued if it's a multiple value * @param valuePrefix the identifier * @param valueSuffix the display name * @param valueEditor the value editor */ public ProtectedItemWrapper( Class<? extends ProtectedItem> clazz, boolean multivalued, String valuePrefix, String valueSuffix, AbstractDialogStringValueEditor valueEditor ) { this.clazz = clazz; this.multivalued = multivalued; this.valuePrefix = valuePrefix; this.valueSuffix = valueSuffix; this.valueEditor = valueEditor; this.values = new ArrayList<String>(); } /** * Creates a new protected item object. Therefore it uses the * dummy ACI, injects the protected item and its value, parses * the ACI and extracts the protected item from the parsed bean. * * @return the parsed protected item * * @throws ParseException if parsing fails */ public ProtectedItem getProtectedItem() throws ParseException { String flatValue = getFlatValue(); String spec = DUMMY; spec = spec.replaceAll( "#identifier#", getIdentifier() ); //$NON-NLS-1$ spec = spec.replaceAll( "#values#", flatValue ); //$NON-NLS-1$ ACIItemParser parser = new ACIItemParser( null ); ItemFirstACIItem aci = null; try { aci = ( ItemFirstACIItem ) parser.parse( spec ); } catch ( ParseException e ) { String msg = NLS .bind( Messages.getString( "ProtectedItemWrapper.error.message" ), new String[] { getIdentifier(), flatValue } ); //$NON-NLS-1$ throw new ParseException( msg, 0 ); } ProtectedItem item = aci.getProtectedItems().iterator().next(); return item; } /** * Sets the protected item. * * @param item the protected item */ public void setProtectedItem( ProtectedItem item ) { assert item.getClass() == getClazz(); // first clear values values.clear(); // switch on userClass type // no value in ProtectedItem.Entry, ProtectedItem.AllUserAttributeTypes and ProtectedItem.AllUserAttributeTypesAndValues if ( item instanceof AttributeTypeItem ) { AttributeTypeItem at = ( AttributeTypeItem ) item; for ( Iterator<AttributeType> it = at.iterator(); it.hasNext(); ) { AttributeType attributeType = it.next(); values.add( attributeType.getName() ); } } else if ( item instanceof AllAttributeValuesItem ) { AllAttributeValuesItem aav = ( AllAttributeValuesItem ) item; for ( Iterator<AttributeType> it = aav.iterator(); it.hasNext(); ) { AttributeType attributeType = it.next(); values.add( attributeType.getName() ); } } else if ( item instanceof AttributeValueItem ) { AttributeValueItem av = ( AttributeValueItem ) item; for ( Iterator<Attribute> it = av.iterator(); it.hasNext(); ) { Attribute entryAttribute = it.next(); values.add( entryAttribute.getId() + "=" + entryAttribute.get() ); //$NON-NLS-1$ } } else if ( item instanceof SelfValueItem ) { SelfValueItem sv = ( SelfValueItem ) item; for ( Iterator<AttributeType> it = sv.iterator(); it.hasNext(); ) { AttributeType attributeType = it.next(); values.add( attributeType.getName() ); } } else if ( item instanceof RangeOfValuesItem ) { RangeOfValuesItem rov = ( RangeOfValuesItem ) item; values.add( rov.getRefinement().toString() ); } else if ( item instanceof MaxValueCountItem ) { MaxValueCountItem mvc = ( MaxValueCountItem ) item; for ( Iterator<MaxValueCountElem> it = mvc.iterator(); it.hasNext(); ) { MaxValueCountElem mvci = it.next(); values.add( mvci.toString() ); } } else if ( item instanceof MaxImmSubItem ) { MaxImmSubItem mis = ( MaxImmSubItem ) item; values.add( Integer.toString( mis.getValue() ) ); } else if ( item instanceof RestrictedByItem ) { RestrictedByItem rb = ( RestrictedByItem ) item; for ( Iterator<RestrictedByElem> it = rb.iterator(); it.hasNext(); ) { RestrictedByElem rbe = it.next(); values.add( rbe.toString() ); } } else if ( item instanceof ClassesItem ) { ClassesItem classes = ( ClassesItem ) item; StringBuilder sb = new StringBuilder(); classes.getClasses().printRefinementToBuffer( sb ); values.add( sb.toString() ); } } /** * Returns a user-friedly string, displayed in the table. * * @return the string */ public String toString() { String flatValue = getFlatValue(); if ( flatValue.length() > 0 ) { flatValue = flatValue.replace( '\r', ' ' ); flatValue = flatValue.replace( '\n', ' ' ); flatValue = ": " + flatValue; //$NON-NLS-1$ if ( flatValue.length() > 40 ) { String temp = flatValue; flatValue = temp.substring( 0, 20 ); flatValue = flatValue + "..."; //$NON-NLS-1$ flatValue = flatValue + temp.substring( temp.length() - 20, temp.length() ); } } return getDisplayName() + " " + flatValue; //$NON-NLS-1$ } /** * Returns the flat value. * * @return the flat value */ private String getFlatValue() { if ( valueEditor == null || values.isEmpty() ) { return ""; //$NON-NLS-1$ } StringBuilder sb = new StringBuilder(); if ( isMultivalued() ) { sb.append( "{ " ); //$NON-NLS-1$ } for ( Iterator<String> it = values.iterator(); it.hasNext(); ) { sb.append( valuePrefix ); String value = it.next(); sb.append( value ); sb.append( valueSuffix ); if ( it.hasNext() ) { sb.append( ", " ); //$NON-NLS-1$ } } if ( isMultivalued() ) { sb.append( " }" ); //$NON-NLS-1$ } return sb.toString(); } /** * Returns the list of values, may be modified. * * @return the modifiable list of values. */ public List<String> getValues() { return values; } /** * Gets the display name. * * @return the display name */ public String getDisplayName() { return CLASS_TO_DISPLAY_MAP.get( clazz ); } /** * Gets the identifier. * * @return the identifier */ public String getIdentifier() { return CLASS_TO_IDENTIFIER_MAP.get( clazz ); } /** * Returns the class of the user class. * * @return the class of the user class. */ public Class<? extends ProtectedItem> getClazz() { return clazz; } /** * Checks if is editable. * * @return true, if is editable */ public boolean isEditable() { return valueEditor != null; } /** * Gets the value editor. * * @return the value editor, may be null. */ public AbstractDialogStringValueEditor getValueEditor() { return valueEditor; } /** * Checks if is multivalued. * * @return true, if is multivalued */ public boolean isMultivalued() { return multivalued; } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/aciitemeditor/src/main/java/org/apache/directory/studio/aciitemeditor/widgets/ACIItemUserClassesComposite.java
plugins/aciitemeditor/src/main/java/org/apache/directory/studio/aciitemeditor/widgets/ACIItemUserClassesComposite.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.aciitemeditor.widgets; import java.text.ParseException; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.List; import org.apache.directory.api.ldap.aci.ProtectedItem; import org.apache.directory.api.ldap.aci.UserClass; import org.apache.directory.studio.aciitemeditor.ACIItemValueWithContext; import org.apache.directory.studio.aciitemeditor.Activator; import org.apache.directory.studio.aciitemeditor.dialogs.MultiValuedDialog; import org.apache.directory.studio.aciitemeditor.model.UserClassWrapper; import org.apache.directory.studio.aciitemeditor.model.UserClassWrapperFactory; import org.apache.directory.studio.valueeditors.AbstractDialogStringValueEditor; import org.eclipse.jface.viewers.ArrayContentProvider; import org.eclipse.jface.viewers.CheckStateChangedEvent; import org.eclipse.jface.viewers.CheckboxTableViewer; import org.eclipse.jface.viewers.DoubleClickEvent; import org.eclipse.jface.viewers.ICheckStateListener; import org.eclipse.jface.viewers.IDoubleClickListener; import org.eclipse.jface.viewers.ISelectionChangedListener; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jface.viewers.LabelProvider; import org.eclipse.jface.viewers.SelectionChangedEvent; 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.Label; import org.eclipse.swt.widgets.Table; /** * This composite contains GUI elements to edit ACI item user classes. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class ACIItemUserClassesComposite extends Composite { /** The context. */ private ACIItemValueWithContext context; /** The inner composite for all the content */ private Composite composite = null; /** The table viewer containing all user classes */ private CheckboxTableViewer tableViewer = null; /** The edit button */ private Button editButton = null; /** The possible user classes, used as input for the table viewer */ private UserClassWrapper[] userClassWrappers = UserClassWrapperFactory.createUserClassWrappers(); /** * Creates a new instance of ACIItemUserClassesComposite. * * @param parent * @param style */ public ACIItemUserClassesComposite( Composite parent, int style ) { super( parent, style ); GridLayout layout = new GridLayout(); layout.horizontalSpacing = 0; layout.verticalSpacing = 0; layout.marginHeight = 0; layout.marginWidth = 0; setLayout( layout ); GridData layoutData = new GridData(); layoutData.horizontalAlignment = GridData.FILL; layoutData.grabExcessHorizontalSpace = true; layoutData.verticalAlignment = GridData.CENTER; setLayoutData( layoutData ); createComposite(); } /** * This method initializes composite * */ private void createComposite() { GridData labelGridData = new GridData(); labelGridData.horizontalSpan = 2; labelGridData.verticalAlignment = GridData.CENTER; labelGridData.grabExcessHorizontalSpace = true; labelGridData.horizontalAlignment = GridData.FILL; GridLayout gridLayout = new GridLayout(); gridLayout.makeColumnsEqualWidth = false; gridLayout.numColumns = 2; GridData gridData = new GridData(); gridData.horizontalAlignment = GridData.FILL; gridData.grabExcessHorizontalSpace = true; gridData.verticalSpan = 1; gridData.verticalAlignment = GridData.BEGINNING; composite = new Composite( this, SWT.NONE ); composite.setLayoutData( gridData ); composite.setLayout( gridLayout ); Label label = new Label( composite, SWT.NONE ); label.setText( Messages.getString( "ACIItemUserClassesComposite.description" ) ); //$NON-NLS-1$ label.setLayoutData( labelGridData ); createTable(); createButtonComposite(); } /** * This method initializes table and table viewer * */ private void createTable() { GridData tableGridData = new GridData(); tableGridData.grabExcessHorizontalSpace = true; tableGridData.verticalAlignment = GridData.FILL; tableGridData.horizontalAlignment = GridData.FILL; Table table = new Table( composite, SWT.BORDER | SWT.CHECK ); table.setHeaderVisible( false ); table.setLayoutData( tableGridData ); table.setLinesVisible( false ); tableViewer = new CheckboxTableViewer( table ); tableViewer.setContentProvider( new ArrayContentProvider() ); tableViewer.setLabelProvider( new UserClassesLabelProvider() ); tableViewer.setInput( userClassWrappers ); tableViewer.addSelectionChangedListener( new ISelectionChangedListener() { @Override public void selectionChanged( SelectionChangedEvent event ) { userClassSelected(); } } ); tableViewer.addCheckStateListener( new ICheckStateListener() { @Override public void checkStateChanged( CheckStateChangedEvent event ) { userClassChecked(); } } ); tableViewer.addDoubleClickListener( new IDoubleClickListener() { @Override public void doubleClick( DoubleClickEvent event ) { if ( editButton.isEnabled() ) { editUserClass(); } } } ); } /** * This method initializes buttons * */ private void createButtonComposite() { GridData reverseSelectionButtonGridData = new GridData(); reverseSelectionButtonGridData.horizontalAlignment = GridData.FILL; reverseSelectionButtonGridData.grabExcessHorizontalSpace = false; reverseSelectionButtonGridData.verticalAlignment = GridData.BEGINNING; reverseSelectionButtonGridData.widthHint = Activator.getButtonWidth( this ); GridData deselectAllButtonGridData = new GridData(); deselectAllButtonGridData.horizontalAlignment = GridData.FILL; deselectAllButtonGridData.grabExcessHorizontalSpace = false; deselectAllButtonGridData.verticalAlignment = GridData.BEGINNING; deselectAllButtonGridData.widthHint = Activator.getButtonWidth( this ); GridData selectAllButtonGridData = new GridData(); selectAllButtonGridData.horizontalAlignment = GridData.FILL; selectAllButtonGridData.grabExcessHorizontalSpace = false; selectAllButtonGridData.verticalAlignment = GridData.BEGINNING; selectAllButtonGridData.widthHint = Activator.getButtonWidth( this ); GridData editButtonGridData = new GridData(); editButtonGridData.horizontalAlignment = GridData.FILL; editButtonGridData.grabExcessHorizontalSpace = false; editButtonGridData.verticalAlignment = GridData.BEGINNING; editButtonGridData.widthHint = Activator.getButtonWidth( this ); GridLayout gridLayout = new GridLayout(); gridLayout.marginWidth = 0; gridLayout.marginHeight = 0; GridData gridData = new GridData(); gridData.horizontalAlignment = GridData.CENTER; gridData.grabExcessHorizontalSpace = false; gridData.grabExcessVerticalSpace = false; gridData.verticalAlignment = GridData.FILL; Composite buttonComposite = new Composite( composite, SWT.NONE ); buttonComposite.setLayoutData( gridData ); buttonComposite.setLayout( gridLayout ); editButton = new Button( buttonComposite, SWT.NONE ); editButton.setText( Messages.getString( "ACIItemUserClassesComposite.edit.button" ) ); //$NON-NLS-1$ editButton.setLayoutData( editButtonGridData ); editButton.addSelectionListener( new SelectionAdapter() { @Override public void widgetSelected( SelectionEvent event ) { editUserClass(); } } ); editButton.setEnabled( false ); Button selectAllButton = new Button( buttonComposite, SWT.NONE ); selectAllButton.setText( Messages.getString( "ACIItemUserClassesComposite.selectAll.button" ) ); //$NON-NLS-1$ selectAllButton.setLayoutData( selectAllButtonGridData ); selectAllButton.addSelectionListener( new SelectionAdapter() { @Override public void widgetSelected( SelectionEvent event ) { tableViewer.setCheckedElements( userClassWrappers ); refreshTable(); } } ); Button deselectAllButton = new Button( buttonComposite, SWT.NONE ); deselectAllButton.setText( Messages.getString( "ACIItemUserClassesComposite.deselectAll.button" ) ); //$NON-NLS-1$ deselectAllButton.setLayoutData( deselectAllButtonGridData ); deselectAllButton.addSelectionListener( new SelectionAdapter() { @Override public void widgetSelected( SelectionEvent event ) { tableViewer.setCheckedElements( new ProtectedItem[0] ); refreshTable(); } } ); Button reverseSelectionButton = new Button( buttonComposite, SWT.NONE ); reverseSelectionButton.setText( Messages.getString( "ACIItemUserClassesComposite.revert.buton" ) ); //$NON-NLS-1$ reverseSelectionButton.setLayoutData( reverseSelectionButtonGridData ); reverseSelectionButton.addSelectionListener( new SelectionAdapter() { @Override public void widgetSelected( SelectionEvent event ) { List<Object> elements = new ArrayList<Object>(); elements.addAll( Arrays.asList( userClassWrappers ) ); elements.removeAll( Arrays.asList( tableViewer.getCheckedElements() ) ); tableViewer.setCheckedElements( elements.toArray() ); refreshTable(); } } ); } /** * The label provider used for this table viewer. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ private class UserClassesLabelProvider extends LabelProvider { /** * Returns the error icon if the user class is checked and invalid. * * @param element the element * * @return the image */ public Image getImage( Object element ) { if ( element instanceof UserClassWrapper ) { UserClassWrapper wrapper = ( UserClassWrapper ) element; if ( tableViewer.getChecked( wrapper ) ) { try { wrapper.getUserClass(); } catch ( ParseException e ) { return Activator.getDefault().getImage( Messages.getString( "ACIItemUserClassesComposite.error.icon" ) ); //$NON-NLS-1$ } } } return null; } } /** * Sets the context. * * @param context the context */ public void setContext( ACIItemValueWithContext context ) { this.context = context; } /** * Sets the user classes. * * @param userClasses the user classes */ public void setUserClasses( Collection<UserClass> userClasses ) { // reset first for ( UserClassWrapper userClassWrapper : userClassWrappers ) { tableViewer.setChecked( userClassWrapper, false ); } for ( UserClass userClass : userClasses ) { for ( UserClassWrapper userClassWrapper : userClassWrappers ) { if ( userClassWrapper.getClazz() == userClass.getClass() ) { userClassWrapper.setUserClass( userClass ); tableViewer.setChecked( userClassWrapper, true ); } } } refreshTable(); } /** * Returns the user classes as selected by the user. * * @return the user classes * @throws ParseException if the user classes or its values are not valid. */ public Collection<UserClass> getUserClasses() throws ParseException { Collection<UserClass> userClasses = new ArrayList<UserClass>(); for ( UserClassWrapper userClassWrapper : userClassWrappers ) { if ( tableViewer.getChecked( userClassWrapper ) ) { UserClass userClass = userClassWrapper.getUserClass(); userClasses.add( userClass ); } } return userClasses; } /** * Shows or hides this composite. * * @param visible true if visible */ public void setVisible( boolean visible ) { super.setVisible( visible ); if ( visible ) { ( ( GridData ) getLayoutData() ).heightHint = -1; } else { ( ( GridData ) getLayoutData() ).heightHint = 0; } } /** * * @return the user class that is selected in the table viewer, or null. */ private UserClassWrapper getSelectedUserClassWrapper() { IStructuredSelection selection = ( IStructuredSelection ) tableViewer.getSelection(); if ( !selection.isEmpty() ) { Object element = selection.getFirstElement(); if ( element instanceof UserClassWrapper ) { return ( UserClassWrapper ) element; } } return null; } /** * Called, when a user class is selected in the table viewer. * - enables/disables the edit button * */ private void userClassSelected() { UserClassWrapper userClassWrapper = getSelectedUserClassWrapper(); if ( ( userClassWrapper == null ) || !userClassWrapper.isEditable() ) { editButton.setEnabled( false ); } else { editButton.setEnabled( true ); } } /** * Called, when a user class checkbox is checked or unchecked. * */ private void userClassChecked() { refreshTable(); } /** * Called, when pushing the edit button. Opens the editor. */ private void editUserClass() { UserClassWrapper userClassWrapper = getSelectedUserClassWrapper(); AbstractDialogStringValueEditor editor = userClassWrapper.getValueEditor(); if ( editor != null ) { MultiValuedDialog dialog = new MultiValuedDialog( getShell(), userClassWrapper.getDisplayName(), userClassWrapper.getValues(), context, editor ); dialog.open(); refreshTable(); } } /** * Refreshes the table viewer. */ private void refreshTable() { tableViewer.refresh(); } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/aciitemeditor/src/main/java/org/apache/directory/studio/aciitemeditor/widgets/ACIItemProtectedItemsComposite.java
plugins/aciitemeditor/src/main/java/org/apache/directory/studio/aciitemeditor/widgets/ACIItemProtectedItemsComposite.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.aciitemeditor.widgets; import java.text.ParseException; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.List; import org.apache.directory.api.ldap.aci.ProtectedItem; import org.apache.directory.studio.aciitemeditor.ACIItemValueWithContext; import org.apache.directory.studio.aciitemeditor.Activator; import org.apache.directory.studio.aciitemeditor.dialogs.MultiValuedDialog; import org.apache.directory.studio.aciitemeditor.model.ProtectedItemWrapper; import org.apache.directory.studio.aciitemeditor.model.ProtectedItemWrapperFactory; import org.apache.directory.studio.ldapbrowser.core.model.IAttribute; import org.apache.directory.studio.ldapbrowser.core.model.IValue; import org.apache.directory.studio.ldapbrowser.core.model.impl.Attribute; import org.apache.directory.studio.ldapbrowser.core.model.impl.Value; import org.apache.directory.studio.valueeditors.AbstractDialogStringValueEditor; import org.eclipse.jface.viewers.ArrayContentProvider; import org.eclipse.jface.viewers.CellEditor; import org.eclipse.jface.viewers.CheckStateChangedEvent; import org.eclipse.jface.viewers.CheckboxTableViewer; import org.eclipse.jface.viewers.DoubleClickEvent; import org.eclipse.jface.viewers.ICheckStateListener; import org.eclipse.jface.viewers.IDoubleClickListener; import org.eclipse.jface.viewers.ISelectionChangedListener; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jface.viewers.LabelProvider; import org.eclipse.jface.viewers.SelectionChangedEvent; 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.Label; import org.eclipse.swt.widgets.Table; /** * This composite contains GUI elements to edit ACI item protected items. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class ACIItemProtectedItemsComposite extends Composite { /** The context. */ private ACIItemValueWithContext context; /** The inner composite for all the content */ private Composite composite = null; /** The table viewer containing all protected items */ private CheckboxTableViewer tableViewer = null; /** The edit button */ private Button editButton = null; /** The possible protected items, used as input for the table viewer */ private ProtectedItemWrapper[] protectedItemWrappers = ProtectedItemWrapperFactory.createProtectedItemWrappers(); /** * Creates a new instance of ACIItemProtectedItemsComposite. * * @param parent * @param style */ public ACIItemProtectedItemsComposite( Composite parent, int style ) { super( parent, style ); GridLayout layout = new GridLayout(); layout.horizontalSpacing = 0; layout.verticalSpacing = 0; layout.marginHeight = 0; layout.marginWidth = 0; setLayout( layout ); GridData layoutData = new GridData(); layoutData.horizontalAlignment = GridData.FILL; layoutData.grabExcessHorizontalSpace = true; layoutData.verticalAlignment = GridData.CENTER; setLayoutData( layoutData ); createComposite(); } /** * This method initializes composite * */ private void createComposite() { GridData labelGridData = new GridData(); labelGridData.horizontalSpan = 2; labelGridData.verticalAlignment = GridData.CENTER; labelGridData.grabExcessHorizontalSpace = true; labelGridData.horizontalAlignment = GridData.FILL; GridLayout gridLayout = new GridLayout(); gridLayout.makeColumnsEqualWidth = false; gridLayout.numColumns = 2; GridData gridData = new GridData(); gridData.horizontalAlignment = GridData.FILL; gridData.grabExcessHorizontalSpace = true; gridData.verticalSpan = 1; gridData.verticalAlignment = GridData.BEGINNING; composite = new Composite( this, SWT.NONE ); composite.setLayoutData( gridData ); composite.setLayout( gridLayout ); Label label = new Label( composite, SWT.NONE ); label.setText( Messages.getString( "ACIItemProtectedItemsComposite.description" ) ); //$NON-NLS-1$ label.setLayoutData( labelGridData ); createTable(); createButtonComposite(); } /** * This method initializes table and table viewer * */ private void createTable() { GridData tableGridData = new GridData(); tableGridData.grabExcessHorizontalSpace = true; tableGridData.verticalAlignment = GridData.FILL; tableGridData.horizontalAlignment = GridData.FILL; //tableGridData.heightHint = 100; Table table = new Table( composite, SWT.BORDER | SWT.CHECK ); table.setHeaderVisible( false ); table.setLayoutData( tableGridData ); table.setLinesVisible( false ); tableViewer = new CheckboxTableViewer( table ); tableViewer.setContentProvider( new ArrayContentProvider() ); tableViewer.setLabelProvider( new ProtectedItemsLabelProvider() ); tableViewer.setInput( protectedItemWrappers ); tableViewer.addSelectionChangedListener( new ISelectionChangedListener() { public void selectionChanged( SelectionChangedEvent event ) { protectedItemSelected(); } } ); tableViewer.addCheckStateListener( new ICheckStateListener() { public void checkStateChanged( CheckStateChangedEvent event ) { protectedItemChecked(); } } ); tableViewer.addDoubleClickListener( new IDoubleClickListener() { public void doubleClick( DoubleClickEvent event ) { if ( editButton.isEnabled() ) { editProtectedItem(); } } } ); } /** * This method initializes buttons * */ private void createButtonComposite() { GridData reverseSelectionButtonGridData = new GridData(); reverseSelectionButtonGridData.horizontalAlignment = GridData.FILL; reverseSelectionButtonGridData.grabExcessHorizontalSpace = false; reverseSelectionButtonGridData.verticalAlignment = GridData.BEGINNING; reverseSelectionButtonGridData.widthHint = Activator.getButtonWidth( this ); GridData deselectAllButtonGridData = new GridData(); deselectAllButtonGridData.horizontalAlignment = GridData.FILL; deselectAllButtonGridData.grabExcessHorizontalSpace = false; deselectAllButtonGridData.verticalAlignment = GridData.BEGINNING; deselectAllButtonGridData.widthHint = Activator.getButtonWidth( this ); GridData selectAllButtonGridData = new GridData(); selectAllButtonGridData.horizontalAlignment = GridData.FILL; selectAllButtonGridData.grabExcessHorizontalSpace = false; selectAllButtonGridData.verticalAlignment = GridData.BEGINNING; selectAllButtonGridData.widthHint = Activator.getButtonWidth( this ); GridData editButtonGridData = new GridData(); editButtonGridData.horizontalAlignment = GridData.FILL; editButtonGridData.grabExcessHorizontalSpace = false; editButtonGridData.verticalAlignment = GridData.BEGINNING; editButtonGridData.widthHint = Activator.getButtonWidth( this ); GridLayout gridLayout = new GridLayout(); gridLayout.marginWidth = 0; gridLayout.marginHeight = 0; GridData gridData = new GridData(); gridData.horizontalAlignment = GridData.CENTER; gridData.grabExcessHorizontalSpace = false; gridData.grabExcessVerticalSpace = false; gridData.verticalAlignment = GridData.FILL; Composite buttonComposite = new Composite( composite, SWT.NONE ); buttonComposite.setLayoutData( gridData ); buttonComposite.setLayout( gridLayout ); editButton = new Button( buttonComposite, SWT.NONE ); editButton.setText( Messages.getString( "ACIItemProtectedItemsComposite.edit.button" ) ); //$NON-NLS-1$ editButton.setLayoutData( editButtonGridData ); editButton.addSelectionListener( new SelectionAdapter() { public void widgetSelected( SelectionEvent e ) { editProtectedItem(); } } ); editButton.setEnabled( false ); Button selectAllButton = new Button( buttonComposite, SWT.NONE ); selectAllButton.setText( Messages.getString( "ACIItemProtectedItemsComposite.selectAll.button" ) ); //$NON-NLS-1$ selectAllButton.setLayoutData( selectAllButtonGridData ); selectAllButton.addSelectionListener( new SelectionAdapter() { public void widgetSelected( SelectionEvent e ) { tableViewer.setCheckedElements( protectedItemWrappers ); refreshTable(); } } ); Button deselectAllButton = new Button( buttonComposite, SWT.NONE ); deselectAllButton.setText( Messages.getString( "ACIItemProtectedItemsComposite.deselectAll.button" ) ); //$NON-NLS-1$ deselectAllButton.setLayoutData( deselectAllButtonGridData ); deselectAllButton.addSelectionListener( new SelectionAdapter() { public void widgetSelected( SelectionEvent e ) { tableViewer.setCheckedElements( new ProtectedItem[0] ); refreshTable(); } } ); Button reverseSelectionButton = new Button( buttonComposite, SWT.NONE ); reverseSelectionButton.setText( Messages.getString( "ACIItemProtectedItemsComposite.revers.button" ) ); //$NON-NLS-1$ reverseSelectionButton.setLayoutData( reverseSelectionButtonGridData ); reverseSelectionButton.addSelectionListener( new SelectionAdapter() { public void widgetSelected( SelectionEvent e ) { List<Object> elements = new ArrayList<Object>(); elements.addAll( Arrays.asList( protectedItemWrappers ) ); elements.removeAll( Arrays.asList( tableViewer.getCheckedElements() ) ); tableViewer.setCheckedElements( elements.toArray() ); refreshTable(); } } ); } /** * The label provider used for this table viewer. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ private class ProtectedItemsLabelProvider extends LabelProvider { /** * Returns the error icon if the protected item is checked and invalid. * * @param element the element * * @return the image */ public Image getImage( Object element ) { if ( element instanceof ProtectedItemWrapper ) { ProtectedItemWrapper wrapper = ( ProtectedItemWrapper ) element; if ( tableViewer.getChecked( wrapper ) ) { try { wrapper.getProtectedItem(); } catch ( ParseException e ) { return Activator.getDefault().getImage( Messages.getString( "ACIItemProtectedItemsComposite.error.icon" ) ); //$NON-NLS-1$ } } } return null; } } /** * Sets the context. * * @param context the context */ public void setContext( ACIItemValueWithContext context ) { this.context = context; } /** * Sets the protected items. * * @param protectedItems */ public void setProtectedItems( Collection<ProtectedItem> protectedItems ) { // reset first for ( ProtectedItemWrapper protectedItemWrapper : protectedItemWrappers ) { tableViewer.setChecked( protectedItemWrapper, false ); } for ( ProtectedItem item : protectedItems ) { for ( ProtectedItemWrapper protectedItemWrapper : protectedItemWrappers ) { if ( protectedItemWrapper.getClazz() == item.getClass() ) { protectedItemWrapper.setProtectedItem( item ); tableViewer.setChecked( protectedItemWrapper, true ); } } } refreshTable(); } /** * Returns the protected items as selected by the user. * * @return the protected items * @throws ParseException if the protected items or its values are not valid. */ public Collection<ProtectedItem> getProtectedItems() throws ParseException { Collection<ProtectedItem> protectedItems = new ArrayList<ProtectedItem>(); for ( ProtectedItemWrapper protectedItemWrapper : protectedItemWrappers ) { if ( tableViewer.getChecked( protectedItemWrapper ) ) { ProtectedItem protectedItem = protectedItemWrapper.getProtectedItem(); protectedItems.add( protectedItem ); } } return protectedItems; } /** * Shows or hides this composite. * * @param visible true if visible */ public void setVisible( boolean visible ) { super.setVisible( visible ); ( ( GridData ) getLayoutData() ).heightHint = visible ? -1 : 0; } /** * * @return the protected item that is selected in the table viewer, or null. */ private ProtectedItemWrapper getSelectedProtectedItemWrapper() { ProtectedItemWrapper protectedItemWrapper = null; IStructuredSelection selection = ( IStructuredSelection ) tableViewer.getSelection(); if ( !selection.isEmpty() ) { Object element = selection.getFirstElement(); if ( element instanceof ProtectedItemWrapper ) { protectedItemWrapper = ( ProtectedItemWrapper ) element; } } return protectedItemWrapper; } /** * Called, when a protected item is selected in the table viewer. * - enables/disables the edit button * */ private void protectedItemSelected() { ProtectedItemWrapper protectedItemWrapper = getSelectedProtectedItemWrapper(); if ( protectedItemWrapper == null || !protectedItemWrapper.isEditable() ) { editButton.setEnabled( false ); } else { editButton.setEnabled( true ); } } /** * Called, when a protected item checkbox is checked or unchecked. */ private void protectedItemChecked() { refreshTable(); } /** * Called, when pushing the edit button. Opens the text editor. * */ private void editProtectedItem() { ProtectedItemWrapper protectedItemWrapper = getSelectedProtectedItemWrapper(); AbstractDialogStringValueEditor valueEditor = protectedItemWrapper.getValueEditor(); if ( valueEditor != null ) { if ( protectedItemWrapper.isMultivalued() ) { MultiValuedDialog dialog = new MultiValuedDialog( getShell(), protectedItemWrapper.getDisplayName(), protectedItemWrapper.getValues(), context, valueEditor ); dialog.open(); refreshTable(); } else { List<String> values = protectedItemWrapper.getValues(); String oldValue = values.isEmpty() ? null : values.get( 0 ); if ( oldValue == null ) { oldValue = ""; //$NON-NLS-1$ } IAttribute attribute = new Attribute( context.getEntry(), "" ); //$NON-NLS-1$ IValue value = new Value( attribute, oldValue ); //$NON-NLS-1$ Object oldRawValue = valueEditor.getRawValue( value ); //$NON-NLS-1$ CellEditor cellEditor = valueEditor.getCellEditor(); cellEditor.setValue( oldRawValue ); cellEditor.activate(); Object newRawValue = cellEditor.getValue(); if ( newRawValue != null ) { String newValue = ( String ) valueEditor.getStringOrBinaryValue( newRawValue ); values.clear(); values.add( newValue ); tableViewer.refresh(); } } } } /** * Refreshes the table viewer. */ private void refreshTable() { tableViewer.refresh(); } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/aciitemeditor/src/main/java/org/apache/directory/studio/aciitemeditor/widgets/ACIItemGeneralComposite.java
plugins/aciitemeditor/src/main/java/org/apache/directory/studio/aciitemeditor/widgets/ACIItemGeneralComposite.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.aciitemeditor.widgets; import java.util.ArrayList; import java.util.List; import org.apache.directory.api.ldap.model.constants.AuthenticationLevel; import org.eclipse.jface.viewers.ArrayContentProvider; import org.eclipse.jface.viewers.ComboViewer; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jface.viewers.LabelProvider; import org.eclipse.jface.viewers.StructuredSelection; import org.eclipse.swt.SWT; import org.eclipse.swt.events.ModifyEvent; import org.eclipse.swt.events.ModifyListener; import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.events.TypedEvent; 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.Label; import org.eclipse.swt.widgets.Spinner; import org.eclipse.swt.widgets.Text; /** * This is used to edit general ACI item properties: * <ul> * <li>identification tag * <li>precedence * <li>authentication level * <li>selection for userFirst or itemFirst * </ul> * * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class ACIItemGeneralComposite extends Composite { /** The identification tag text field */ private Text identificationTagText = null; /** The spinner to select a valid precedence between 0 and 255 */ private Spinner precedenceSpinner = null; /** * The combo viewer is attached to authenticationLevelCombo to work with * AuthenticationLevel objects rather than Strings */ private ComboViewer authenticationLevelComboViewer = null; /** The user first radio button */ private Button userFirstRadioButton = null; /** The item first radio button */ private Button itemFirstRadioButton = null; /** The list with listers */ private List<WidgetModifyListener> listenerList = new ArrayList<WidgetModifyListener>(); /** * Creates a new instance of ACIItemGeneralComposite. * * @param parent * @param style */ public ACIItemGeneralComposite( Composite parent, int style ) { super( parent, style ); GridLayout layout = new GridLayout(); layout.horizontalSpacing = 0; layout.verticalSpacing = 0; layout.marginHeight = 0; layout.marginWidth = 0; setLayout( layout ); GridData layoutData = new GridData(); layoutData.horizontalAlignment = GridData.FILL; layoutData.grabExcessHorizontalSpace = true; layoutData.verticalAlignment = GridData.CENTER; setLayoutData( layoutData ); createComposite(); } /** * This method initializes composite * */ private void createComposite() { GridData identificationTagGridData = new GridData(); identificationTagGridData.grabExcessHorizontalSpace = true; identificationTagGridData.verticalAlignment = GridData.CENTER; identificationTagGridData.horizontalSpan = 2; identificationTagGridData.horizontalAlignment = GridData.FILL; GridData precedenceGridData = new GridData(); precedenceGridData.grabExcessHorizontalSpace = true; precedenceGridData.verticalAlignment = GridData.CENTER; precedenceGridData.horizontalSpan = 2; precedenceGridData.horizontalAlignment = GridData.BEGINNING; precedenceGridData.widthHint = 3 * 12; GridData authenticationLevelGridData = new GridData(); authenticationLevelGridData.grabExcessHorizontalSpace = true; authenticationLevelGridData.verticalAlignment = GridData.CENTER; authenticationLevelGridData.horizontalSpan = 2; authenticationLevelGridData.horizontalAlignment = GridData.FILL; GridLayout gridLayout = new GridLayout(); gridLayout.numColumns = 3; GridData gridData = new GridData(); gridData.horizontalAlignment = GridData.FILL; gridData.grabExcessHorizontalSpace = true; gridData.verticalAlignment = GridData.CENTER; Composite composite = new Composite( this, SWT.NONE ); composite.setLayout( gridLayout ); composite.setLayoutData( gridData ); Label identificationTagLabel = new Label( composite, SWT.NONE ); identificationTagLabel.setText( Messages.getString( "ACIItemGeneralComposite.idTag.label" ) ); //$NON-NLS-1$ identificationTagText = new Text( composite, SWT.BORDER ); identificationTagText.setLayoutData( identificationTagGridData ); identificationTagText.addModifyListener( new ModifyListener() { public void modifyText( ModifyEvent event ) { fire( event ); } } ); Label precedenceLabel = new Label( composite, SWT.NONE ); precedenceLabel.setText( Messages.getString( "ACIItemGeneralComposite.precedence.label" ) ); //$NON-NLS-1$ precedenceSpinner = new Spinner( composite, SWT.BORDER ); precedenceSpinner.setMinimum( 0 ); precedenceSpinner.setMaximum( 255 ); precedenceSpinner.setDigits( 0 ); precedenceSpinner.setIncrement( 1 ); precedenceSpinner.setPageIncrement( 10 ); precedenceSpinner.setSelection( 0 ); precedenceSpinner.setLayoutData( precedenceGridData ); precedenceSpinner.addModifyListener( new ModifyListener() { public void modifyText( ModifyEvent event ) { fire( event ); } } ); Label authenticationLevelLabel = new Label( composite, SWT.NONE ); authenticationLevelLabel.setText( Messages.getString( "ACIItemGeneralComposite.authLevel.label" ) ); //$NON-NLS-1$ Combo authenticationLevelCombo = new Combo( composite, SWT.READ_ONLY ); authenticationLevelCombo.setLayoutData( authenticationLevelGridData ); AuthenticationLevel[] authenticationLevels = new AuthenticationLevel[3]; authenticationLevels[0] = AuthenticationLevel.NONE; authenticationLevels[1] = AuthenticationLevel.SIMPLE; authenticationLevels[2] = AuthenticationLevel.STRONG; authenticationLevelComboViewer = new ComboViewer( authenticationLevelCombo ); authenticationLevelComboViewer.setContentProvider( new ArrayContentProvider() ); authenticationLevelComboViewer.setLabelProvider( new LabelProvider() ); authenticationLevelComboViewer.setInput( authenticationLevels ); authenticationLevelComboViewer.setSelection( new StructuredSelection( AuthenticationLevel.NONE ) ); authenticationLevelCombo.addModifyListener( new ModifyListener() { public void modifyText( ModifyEvent event ) { fire( event ); } } ); Label userOrItemFirstLabel = new Label( composite, SWT.NONE ); userOrItemFirstLabel.setText( Messages.getString( "ACIItemGeneralComposite.userOrItemFirst.label" ) ); //$NON-NLS-1$ userFirstRadioButton = new Button( composite, SWT.RADIO ); userFirstRadioButton.setText( Messages.getString( "ACIItemGeneralComposite.userFirst.label" ) ); //$NON-NLS-1$ userFirstRadioButton.addSelectionListener( new SelectionAdapter() { public void widgetSelected( SelectionEvent event ) { fire( event ); } } ); itemFirstRadioButton = new Button( composite, SWT.RADIO ); itemFirstRadioButton.setText( Messages.getString( "ACIItemGeneralComposite.itemFirst.label" ) ); //$NON-NLS-1$ itemFirstRadioButton.addSelectionListener( new SelectionAdapter() { public void widgetSelected( SelectionEvent event ) { fire( event ); } } ); } /** * Add the listener to the list of listeners. * * @param listener */ public void addWidgetModifyListener( WidgetModifyListener listener ) { checkWidget(); if ( listener == null ) { SWT.error( SWT.ERROR_NULL_ARGUMENT ); } listenerList.add( listener ); } /** * Removes the listener from the list of listeners. * * @param listener */ public void removeWidgetModifyListener( WidgetModifyListener listener ) { checkWidget(); if ( listener == null ) { SWT.error( SWT.ERROR_NULL_ARGUMENT ); } listenerList.remove( listener ); } /** * Fires WidgetModifyEvents. * * @param event the original event */ private void fire( TypedEvent event ) { for ( WidgetModifyListener listener : listenerList ) { listener.widgetModified( new WidgetModifyEvent( this ) ); } } /** * Returns the identification tag. * * @return the identification tag */ public String getIdentificationTag() { return identificationTagText.getText(); } /** * Sets the identification tag * * @param identificationTag the identification tag */ public void setIdentificationTag( String identificationTag ) { identificationTagText.setText( identificationTag ); } /** * Returns the selected precedence. * * @return the selected precedence */ public int getPrecedence() { return precedenceSpinner.getSelection(); } /** * Sets the precedence * * @param precedence the precedence */ public void setPrecedence( int precedence ) { precedenceSpinner.setSelection( precedence ); } /** * Returns the selected authentication level. * * @return the selected authentication level */ public AuthenticationLevel getAuthenticationLevel() { IStructuredSelection selection = ( IStructuredSelection ) authenticationLevelComboViewer.getSelection(); return ( AuthenticationLevel ) selection.getFirstElement(); } /** * Sets the authentication level. * * @param authenticationLevel the authentication level */ public void setAuthenticationLevel( AuthenticationLevel authenticationLevel ) { IStructuredSelection selection = new StructuredSelection( authenticationLevel ); authenticationLevelComboViewer.setSelection( selection ); } /** * Returns true if user first is selected. * * @return true if user first is selected */ public boolean isUserFirst() { return userFirstRadioButton.getSelection(); } /** * Selects user first. */ public void setUserFirst() { userFirstRadioButton.setSelection( true ); itemFirstRadioButton.setSelection( false ); } /** * Returns true if item first is selected. * * @return true if item first is selected */ public boolean isItemFirst() { return itemFirstRadioButton.getSelection(); } /** * Selects item first. */ public void setItemFirst() { itemFirstRadioButton.setSelection( true ); userFirstRadioButton.setSelection( 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/aciitemeditor/src/main/java/org/apache/directory/studio/aciitemeditor/widgets/ACIItemSourceEditorComposite.java
plugins/aciitemeditor/src/main/java/org/apache/directory/studio/aciitemeditor/widgets/ACIItemSourceEditorComposite.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.aciitemeditor.widgets; import java.text.ParseException; import org.apache.directory.api.ldap.aci.ACIItem; import org.apache.directory.api.ldap.aci.ACIItemParser; import org.apache.directory.studio.aciitemeditor.ACIItemValueWithContext; import org.apache.directory.studio.aciitemeditor.Activator; import org.apache.directory.studio.aciitemeditor.sourceeditor.ACISourceViewerConfiguration; import org.eclipse.jface.resource.JFaceResources; import org.eclipse.jface.text.Document; import org.eclipse.jface.text.IDocument; import org.eclipse.jface.text.IRegion; import org.eclipse.jface.text.Region; import org.eclipse.jface.text.source.SourceViewer; import org.eclipse.jface.text.source.SourceViewerConfiguration; import org.eclipse.swt.SWT; import org.eclipse.swt.graphics.Font; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Composite; /** * This composite contains the source editor. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class ACIItemSourceEditorComposite extends Composite { /** The source editor */ private SourceViewer sourceEditor; /** The source editor configuration. */ private SourceViewerConfiguration configuration; /** * Creates a new instance of ACIItemSourceEditorComposite. * * @param parent * @param style */ public ACIItemSourceEditorComposite( Composite parent, int style ) { super( parent, style ); setLayout( new GridLayout() ); createSourceEditor(); } /** * Creates and configures the source editor. * */ private void createSourceEditor() { // create source editor sourceEditor = new SourceViewer( this, null, null, false, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL ); sourceEditor.getControl().setLayoutData( new GridData( SWT.FILL, SWT.FILL, true, true ) ); // setup basic configuration configuration = new ACISourceViewerConfiguration(); sourceEditor.configure( configuration ); // set text font Font font = JFaceResources.getFont( JFaceResources.TEXT_FONT ); sourceEditor.getTextWidget().setFont( font ); // setup document IDocument document = new Document(); sourceEditor.setDocument( document ); } /** * Sets the input to the source editor. * A syntax check is performed before setting the input, an * invalid syntax causes a ParseException. * * @param input the valid string representation of the ACI item * @throws ParseException it the syntax check fails. */ public void setInput( String input ) throws ParseException { ACIItemParser parser = Activator.getDefault().getACIItemParser(); parser.parse( input ); forceSetInput( input ); } /** * Set the input to the source editor without a syntax check. * * @param input The string representation of the ACI item, may be invalid */ public void forceSetInput( String input ) { sourceEditor.getDocument().set( input ); // format IRegion region = new Region( 0, sourceEditor.getDocument().getLength() ); configuration.getContentFormatter( sourceEditor ).format( sourceEditor.getDocument(), region ); } /** * Returns the string representation of the ACI item. * A syntax check is performed before returning the input, an * invalid syntax causes a ParseException. * * @return the valid string representation of the ACI item * @throws ParseException it the syntax check fails. */ public String getInput() throws ParseException { String input = forceGetInput(); // strip new lines input = input.replaceAll( "\\n", " " ); //$NON-NLS-1$ //$NON-NLS-2$ input = input.replaceAll( "\\r", " " ); //$NON-NLS-1$ //$NON-NLS-2$ ACIItemParser parser = Activator.getDefault().getACIItemParser(); ACIItem aciItem = parser.parse( input ); String aci = ""; //$NON-NLS-1$ if ( aciItem != null ) { aci = aciItem.toString(); } return aci; } /** * Returns the string representation of the ACI item without syntax check. * In other words only the text in the source editor is returned. * * @return the string representation of the ACI item, may be invalid */ public String forceGetInput() { return sourceEditor.getDocument().get(); } /** * Sets the context. * * @param context the context */ public void setContext( ACIItemValueWithContext context ) { } /** * Formats the content. */ public void format() { IRegion region = new Region( 0, sourceEditor.getDocument().getLength() ); configuration.getContentFormatter( sourceEditor ).format( sourceEditor.getDocument(), region ); } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/aciitemeditor/src/main/java/org/apache/directory/studio/aciitemeditor/widgets/ACIItemGrantsAndDenialsComposite.java
plugins/aciitemeditor/src/main/java/org/apache/directory/studio/aciitemeditor/widgets/ACIItemGrantsAndDenialsComposite.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.aciitemeditor.widgets; import java.text.ParseException; import java.util.ArrayList; import java.util.Collection; import java.util.LinkedList; import java.util.List; import org.apache.directory.api.ldap.aci.GrantAndDenial; import org.apache.directory.studio.aciitemeditor.Activator; import org.eclipse.jface.viewers.ArrayContentProvider; import org.eclipse.jface.viewers.CellEditor; import org.eclipse.jface.viewers.CheckboxCellEditor; import org.eclipse.jface.viewers.ICellModifier; import org.eclipse.jface.viewers.ITableLabelProvider; import org.eclipse.jface.viewers.ITreeContentProvider; import org.eclipse.jface.viewers.LabelProvider; 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.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.Item; import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Tree; import org.eclipse.swt.widgets.TreeColumn; /** * This composite contains GUI elements to edit ACI item grants and denials. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class ACIItemGrantsAndDenialsComposite extends Composite { /** The tree viewer containing all grants and denials */ private TreeViewer treeViewer = null; /** The undo button */ private Button undoButton = null; /** The redo button */ private Button redoButton = null; /** Colum 1 */ private static final String PERMISSION = Messages.getString( "ACIItemGrantsAndDenialsComposite.column1.header" ); //$NON-NLS-1$ /** Colum2 */ private static final String STATE = Messages.getString( "ACIItemGrantsAndDenialsComposite.column2.header" ); //$NON-NLS-1$ /** The colums */ private static final String[] COLUMNS = new String[] { PERMISSION, STATE }; /** The undo/redo stack size */ private static final int MAX_STACK_SIZE = 25; /** Used as input for the tree viewer */ private GrantAndDenialCategory[] grantAndDenialCategories = new GrantAndDenialCategory[] { new GrantAndDenialCategory( Messages.getString( "ACIItemGrantsAndDenialsComposite.category.read" ), true, new GrantAndDenialWrapper[] //$NON-NLS-1$ { new GrantAndDenialWrapper( GrantAndDenial.GRANT_BROWSE, GrantAndDenial.DENY_BROWSE ), new GrantAndDenialWrapper( GrantAndDenial.GRANT_READ, GrantAndDenial.DENY_READ ), new GrantAndDenialWrapper( GrantAndDenial.GRANT_COMPARE, GrantAndDenial.DENY_COMPARE ), new GrantAndDenialWrapper( GrantAndDenial.GRANT_FILTER_MATCH, GrantAndDenial.DENY_FILTER_MATCH ), new GrantAndDenialWrapper( GrantAndDenial.GRANT_RETURN_DN, GrantAndDenial.DENY_RETURN_DN ) } ), new GrantAndDenialCategory( Messages.getString( "ACIItemGrantsAndDenialsComposite.category.modify" ), true, new GrantAndDenialWrapper[] //$NON-NLS-1$ { new GrantAndDenialWrapper( GrantAndDenial.GRANT_ADD, GrantAndDenial.DENY_ADD ), new GrantAndDenialWrapper( GrantAndDenial.GRANT_MODIFY, GrantAndDenial.DENY_MODIFY ), new GrantAndDenialWrapper( GrantAndDenial.GRANT_REMOVE, GrantAndDenial.DENY_REMOVE ), new GrantAndDenialWrapper( GrantAndDenial.GRANT_RENAME, GrantAndDenial.DENY_RENAME ) } ), new GrantAndDenialCategory( Messages.getString( "ACIItemGrantsAndDenialsComposite.category.advanced" ), false, new GrantAndDenialWrapper[] //$NON-NLS-1$ { new GrantAndDenialWrapper( GrantAndDenial.GRANT_EXPORT, GrantAndDenial.DENY_EXPORT ), new GrantAndDenialWrapper( GrantAndDenial.GRANT_IMPORT, GrantAndDenial.DENY_IMPORT ), new GrantAndDenialWrapper( GrantAndDenial.GRANT_INVOKE, GrantAndDenial.DENY_INVOKE ), new GrantAndDenialWrapper( GrantAndDenial.GRANT_DISCLOSE_ON_ERROR, GrantAndDenial.DENY_DISCLOSE_ON_ERROR ) } ) }; /** * A GrantAndDenialCategory is used to categorize grants and denials in a tree. */ private class GrantAndDenialCategory { /** The category name, displayed in tree */ private String name; /** The initial expanded state */ private boolean expanded; /** The grants and denials wrappers display under this category */ private GrantAndDenialWrapper[] grantAndDenialWrappers; /** * Creates a new instance of GrantAndDenialCategory. * * @param name the category name, displayed in tree * @param expanded true if category should be initially expanded * @param grantAndDenialWrappers the grants and denials wrappers display under this category */ private GrantAndDenialCategory( String name, boolean expanded, GrantAndDenialWrapper[] grantAndDenialWrappers ) { this.name = name; this.expanded = expanded; this.grantAndDenialWrappers = grantAndDenialWrappers; } } /** * A GrantAndDenialWrapper is used to display grants and denials in tree and to * track the current state (not specified, grant or deny). Additional it provides * undo/redo functionality. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ private class GrantAndDenialWrapper { /** The grant */ private GrantAndDenial grant; /** The denial */ private GrantAndDenial denial; /** The current state: null=not specified, grant or denial */ private GrantAndDenial activeGrantAndDenial; /** List containing previous states of activeGrandAndDenial */ private List<GrantAndDenial> undoStack; /** List containing "future" states of activeGrandAndDenial */ private List<GrantAndDenial> redoStack; /** * Creates a new instance of GrantAndDenialWrapper. * * @param grant * @param denial */ private GrantAndDenialWrapper( GrantAndDenial grant, GrantAndDenial denial ) { this.grant = grant; this.denial = denial; this.activeGrantAndDenial = null; undoStack = new LinkedList<GrantAndDenial>(); redoStack = new LinkedList<GrantAndDenial>(); } } /** * Creates a new instance of ACIItemGrantsAndDenialsComposite. * * @param parent * @param style */ public ACIItemGrantsAndDenialsComposite( Composite parent, int style ) { super( parent, style ); GridLayout layout = new GridLayout(); layout.makeColumnsEqualWidth = false; layout.numColumns = 2; setLayout( layout ); GridData layoutData = new GridData(); layoutData.grabExcessHorizontalSpace = true; layoutData.grabExcessVerticalSpace = true; layoutData.horizontalAlignment = GridData.FILL; layoutData.verticalAlignment = GridData.FILL; setLayoutData( layoutData ); GridData labelGridData = new GridData(); labelGridData.horizontalSpan = 2; labelGridData.verticalAlignment = GridData.CENTER; labelGridData.grabExcessHorizontalSpace = true; labelGridData.horizontalAlignment = GridData.FILL; Label label = new Label( this, SWT.NONE ); label.setText( Messages.getString( "ACIItemGrantsAndDenialsComposite.description" ) ); //$NON-NLS-1$ label.setLayoutData( labelGridData ); createTree(); createButtonComposite(); } /** * This method initializes tree * */ private void createTree() { GridData tableGridData = new GridData( GridData.FILL_BOTH ); tableGridData.grabExcessHorizontalSpace = true; tableGridData.grabExcessVerticalSpace = true; tableGridData.verticalAlignment = GridData.FILL; tableGridData.horizontalAlignment = GridData.FILL; //tableGridData.heightHint = 100; Tree tree = new Tree( this, SWT.SINGLE | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.HIDE_SELECTION ); tree.setHeaderVisible( true ); tree.setLayoutData( tableGridData ); tree.setLinesVisible( true ); TreeColumn treeColumn1 = new TreeColumn( tree, SWT.LEFT, 0 ); treeColumn1.setText( COLUMNS[0] ); treeColumn1.setWidth( 160 ); TreeColumn treeColumn2 = new TreeColumn( tree, SWT.LEFT, 1 ); treeColumn2.setText( COLUMNS[1] ); treeColumn2.setWidth( 80 ); // TreeColumn c3 = new TreeColumn( tree, SWT.LEFT, 2 ); // c3.setText( " " ); //$NON-NLS-1$ // c3.setWidth( 0 ); treeViewer = new TreeViewer( tree ); treeViewer.setUseHashlookup( true ); treeViewer.setColumnProperties( COLUMNS ); ICellModifier cellModifier = new GrantsAndDenialsCellModifier(); treeViewer.setCellModifier( cellModifier ); CellEditor[] cellEditors = new CellEditor[] { null, new CheckboxCellEditor( tree ), null }; treeViewer.setCellEditors( cellEditors ); treeViewer.setContentProvider( new GrantsAndDenialsContentProvider() ); treeViewer.setLabelProvider( new GrantsAndDenialsLabelProvider() ); treeViewer.setInput( grantAndDenialCategories ); // set expanded state List<GrantAndDenialCategory> expandedList = new ArrayList<GrantAndDenialCategory>(); for ( GrantAndDenialCategory grantAndDenialCategory : grantAndDenialCategories ) { if ( grantAndDenialCategory.expanded ) { expandedList.add( grantAndDenialCategory ); } } treeViewer.setExpandedElements( expandedList.toArray() ); } /** * This method initializes buttonComposite * */ private void createButtonComposite() { GridData deselectAllButtonGridData = new GridData(); deselectAllButtonGridData.horizontalAlignment = GridData.FILL; deselectAllButtonGridData.grabExcessHorizontalSpace = false; deselectAllButtonGridData.verticalAlignment = GridData.BEGINNING; deselectAllButtonGridData.widthHint = Activator.getButtonWidth( this ); GridData denyAllButtonGridData = new GridData(); denyAllButtonGridData.horizontalAlignment = GridData.FILL; denyAllButtonGridData.grabExcessHorizontalSpace = false; denyAllButtonGridData.verticalAlignment = GridData.BEGINNING; denyAllButtonGridData.widthHint = Activator.getButtonWidth( this ); GridData grantAllButtonGridData = new GridData(); grantAllButtonGridData.horizontalAlignment = GridData.FILL; grantAllButtonGridData.grabExcessHorizontalSpace = false; grantAllButtonGridData.verticalAlignment = GridData.BEGINNING; grantAllButtonGridData.widthHint = Activator.getButtonWidth( this ); GridData undoButtonGridData = new GridData(); undoButtonGridData.horizontalAlignment = GridData.FILL; undoButtonGridData.grabExcessHorizontalSpace = false; undoButtonGridData.verticalAlignment = GridData.BEGINNING; undoButtonGridData.widthHint = Activator.getButtonWidth( this ); GridData redoButtonGridData = new GridData(); redoButtonGridData.horizontalAlignment = GridData.FILL; redoButtonGridData.grabExcessHorizontalSpace = false; redoButtonGridData.verticalAlignment = GridData.BEGINNING; redoButtonGridData.widthHint = Activator.getButtonWidth( this ); GridLayout gridLayout = new GridLayout(); gridLayout.marginWidth = 0; gridLayout.marginHeight = 0; GridData gridData = new GridData(); gridData.horizontalAlignment = GridData.CENTER; gridData.grabExcessHorizontalSpace = false; gridData.grabExcessVerticalSpace = false; gridData.verticalAlignment = GridData.FILL; Composite buttonComposite = new Composite( this, SWT.NONE ); buttonComposite.setLayoutData( gridData ); buttonComposite.setLayout( gridLayout ); Button grantAllButton = new Button( buttonComposite, SWT.NONE ); grantAllButton.setText( Messages.getString( "ACIItemGrantsAndDenialsComposite.grantAll.button" ) ); //$NON-NLS-1$ grantAllButton.setLayoutData( grantAllButtonGridData ); grantAllButton.addSelectionListener( new SelectionAdapter() { public void widgetSelected( SelectionEvent event ) { backup(); for ( GrantAndDenialCategory grantAndDenialCategory : grantAndDenialCategories ) { for ( GrantAndDenialWrapper grantAndDenialWrapper : grantAndDenialCategory.grantAndDenialWrappers ) { grantAndDenialWrapper.activeGrantAndDenial = grantAndDenialWrapper.grant; } } treeViewer.refresh(); } } ); Button denyAllButton = new Button( buttonComposite, SWT.NONE ); denyAllButton.setText( Messages.getString( "ACIItemGrantsAndDenialsComposite.denyAll.button" ) ); //$NON-NLS-1$ denyAllButton.setLayoutData( denyAllButtonGridData ); denyAllButton.addSelectionListener( new SelectionAdapter() { public void widgetSelected( SelectionEvent event ) { backup(); for ( GrantAndDenialCategory grantAndDenialCategory : grantAndDenialCategories ) { for ( GrantAndDenialWrapper grantAndDenialWrapper : grantAndDenialCategory.grantAndDenialWrappers ) { grantAndDenialWrapper.activeGrantAndDenial = grantAndDenialWrapper.denial; } } treeViewer.refresh(); } } ); Button deselectAllButton = new Button( buttonComposite, SWT.NONE ); deselectAllButton.setText( Messages.getString( "ACIItemGrantsAndDenialsComposite.deselectAll.button" ) ); //$NON-NLS-1$ deselectAllButton.setLayoutData( deselectAllButtonGridData ); deselectAllButton.addSelectionListener( new SelectionAdapter() { public void widgetSelected( SelectionEvent event ) { backup(); for ( GrantAndDenialCategory grantAndDenialCategory : grantAndDenialCategories ) { for ( GrantAndDenialWrapper grantAndDenialWrapper : grantAndDenialCategory.grantAndDenialWrappers ) { grantAndDenialWrapper.activeGrantAndDenial = null; } } treeViewer.refresh(); } } ); undoButton = new Button( buttonComposite, SWT.NONE ); undoButton.setText( Messages.getString( "ACIItemGrantsAndDenialsComposite.undo.button" ) ); //$NON-NLS-1$ undoButton.setLayoutData( undoButtonGridData ); undoButton.addSelectionListener( new SelectionAdapter() { public void widgetSelected( SelectionEvent event ) { undo(); treeViewer.refresh(); } } ); undoButton.setEnabled( false ); redoButton = new Button( buttonComposite, SWT.NONE ); redoButton.setText( Messages.getString( "ACIItemGrantsAndDenialsComposite.redo.button" ) ); //$NON-NLS-1$ redoButton.setLayoutData( redoButtonGridData ); redoButton.addSelectionListener( new SelectionAdapter() { public void widgetSelected( SelectionEvent event ) { redo(); treeViewer.refresh(); } } ); redoButton.setEnabled( false ); } /** * The ICellModifier user for this tree viewer. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ private class GrantsAndDenialsCellModifier implements ICellModifier { /** * Only GrantAndDenialWrappers and the STATE colum is modifiable. * * @param element the element * @param property the property * * @return true, if can modify */ public boolean canModify( Object element, String property ) { if ( element instanceof GrantAndDenialWrapper ) { return property.equals( STATE ); } return false; } /** * The used CheckboxCellEditor accepts only Booleans. * * @param element the element * @param property the property * * @return the value */ public Object getValue( Object element, String property ) { if ( ( element instanceof GrantAndDenialWrapper ) && property.equals( STATE ) ) { return Boolean.TRUE; } return null; } /** * Performs the tree-state transtion. * * @param element the element * @param value the value * @param property the property */ public void modify( Object element, String property, Object value ) { Object target = element; if ( element instanceof Item ) { target = ( ( Item ) element ).getData(); } if ( target instanceof GrantAndDenialWrapper ) { GrantAndDenialWrapper grantAndDenialWrapper = ( GrantAndDenialWrapper ) target; if ( property.equals( STATE ) ) { backup(); if ( grantAndDenialWrapper.activeGrantAndDenial == null ) { grantAndDenialWrapper.activeGrantAndDenial = grantAndDenialWrapper.grant; } else if ( grantAndDenialWrapper.activeGrantAndDenial == grantAndDenialWrapper.grant ) { grantAndDenialWrapper.activeGrantAndDenial = grantAndDenialWrapper.denial; } else if ( grantAndDenialWrapper.activeGrantAndDenial == grantAndDenialWrapper.denial ) { grantAndDenialWrapper.activeGrantAndDenial = null; } } } treeViewer.refresh(); } } /** * The content provider used for this tree viewer. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ private class GrantsAndDenialsContentProvider extends ArrayContentProvider implements ITreeContentProvider { /** * Only GrantAndDenialCategories have children. * * @param parentElement the parent element * * @return the children */ public Object[] getChildren( Object parentElement ) { if ( parentElement instanceof GrantAndDenialCategory ) { GrantAndDenialCategory cat = ( GrantAndDenialCategory ) parentElement; return cat.grantAndDenialWrappers; } return null; } /** * Not used. * * @param element the element * * @return the parent */ public Object getParent( Object element ) { return null; } /** * Only GrantAndDenialCategories have children. * * @param element the element * * @return true, if has children */ public boolean hasChildren( Object element ) { return ( element instanceof GrantAndDenialCategory ); } } /** * The label provider used for this tree viewer. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ private class GrantsAndDenialsLabelProvider extends LabelProvider implements ITableLabelProvider { /** * The STATE is displayed as image. * * @param element the element * @param columnIndex the column index * * @return the column image */ public Image getColumnImage( Object element, int columnIndex ) { if ( element instanceof GrantAndDenialWrapper ) { GrantAndDenialWrapper grantAndDenialWrapper = ( GrantAndDenialWrapper ) element; switch ( columnIndex ) { case 0: return null; case 1: if ( grantAndDenialWrapper.activeGrantAndDenial == null ) { return Activator.getDefault().getImage( Messages.getString( "ACIItemGrantsAndDenialsComposite.unspecified.icon" ) ); //$NON-NLS-1$ } else if ( grantAndDenialWrapper.activeGrantAndDenial == grantAndDenialWrapper.grant ) { return Activator.getDefault().getImage( Messages.getString( "ACIItemGrantsAndDenialsComposite.grant.icon" ) ); //$NON-NLS-1$ } else if ( grantAndDenialWrapper.activeGrantAndDenial == grantAndDenialWrapper.denial ) { return Activator.getDefault().getImage( Messages.getString( "ACIItemGrantsAndDenialsComposite.deny.icon" ) ); //$NON-NLS-1$ } case 2: return null; } } return null; } /** * Returns GrantAndDenialCategory name or the MicroOperation name. * * @param element the element * @param columnIndex the column index * * @return the column text */ public String getColumnText( Object element, int columnIndex ) { if ( element instanceof GrantAndDenialCategory ) { if ( columnIndex == 0 ) { GrantAndDenialCategory cat = ( GrantAndDenialCategory ) element; return cat.name; } } else if ( ( element instanceof GrantAndDenialWrapper ) && ( columnIndex == 0 ) ) { GrantAndDenialWrapper wrapper = ( GrantAndDenialWrapper ) element; return wrapper.grant.getMicroOperation().getName(); } return ""; //$NON-NLS-1$ } } /** * Sets the grants and denials. * * @param grantsAndDenials */ public void setGrantsAndDenials( Collection<GrantAndDenial> grantsAndDenials ) { for ( GrantAndDenial grantAndDenial : grantsAndDenials ) { for ( GrantAndDenialCategory grantAndDenialCategory : grantAndDenialCategories ) { for ( GrantAndDenialWrapper grantAndDenialWrapper : grantAndDenialCategory.grantAndDenialWrappers ) { if ( grantAndDenialWrapper.grant == grantAndDenial ) { grantAndDenialWrapper.activeGrantAndDenial = grantAndDenialWrapper.grant; } else if ( grantAndDenialWrapper.denial == grantAndDenial ) { grantAndDenialWrapper.activeGrantAndDenial = grantAndDenialWrapper.denial; } } } } treeViewer.refresh(); } /** * Returns the grants and denials as selected by the user. * * @return the grants and denials * @throws ParseException */ public Collection<GrantAndDenial> getGrantsAndDenials() throws ParseException { Collection<GrantAndDenial> grantsAndDenials = new ArrayList<GrantAndDenial>(); for ( GrantAndDenialCategory grantAndDenialCategory : grantAndDenialCategories ) { for ( GrantAndDenialWrapper grantAndDenialWrapper : grantAndDenialCategory.grantAndDenialWrappers ) { if ( grantAndDenialWrapper.activeGrantAndDenial != null ) { grantsAndDenials.add( grantAndDenialWrapper.activeGrantAndDenial ); } } } return grantsAndDenials; } /** * Undos the last modification. */ private void undo() { for ( GrantAndDenialCategory grantAndDenialCategory : grantAndDenialCategories ) { for ( GrantAndDenialWrapper grantAndDenialWrapper : grantAndDenialCategory.grantAndDenialWrappers ) { if ( !grantAndDenialWrapper.undoStack.isEmpty() ) { grantAndDenialWrapper.redoStack.add( 0, grantAndDenialWrapper.activeGrantAndDenial ); grantAndDenialWrapper.activeGrantAndDenial = grantAndDenialWrapper.undoStack.remove( 0 ); } undoButton.setEnabled( !grantAndDenialWrapper.undoStack.isEmpty() ); redoButton.setEnabled( !grantAndDenialWrapper.redoStack.isEmpty() ); } } } /** * Redos the last modification */ private void redo() { for ( GrantAndDenialCategory grantAndDenialCategory : grantAndDenialCategories ) { for ( GrantAndDenialWrapper grantAndDenialWrapper : grantAndDenialCategory.grantAndDenialWrappers ) { if ( !grantAndDenialWrapper.redoStack.isEmpty() ) { grantAndDenialWrapper.undoStack.add( 0, grantAndDenialWrapper.activeGrantAndDenial ); grantAndDenialWrapper.activeGrantAndDenial = grantAndDenialWrapper.redoStack.remove( 0 ); } undoButton.setEnabled( !grantAndDenialWrapper.undoStack.isEmpty() ); redoButton.setEnabled( !grantAndDenialWrapper.redoStack.isEmpty() ); } } } /** * Saves the current state to the undo stack. */ private void backup() { for ( GrantAndDenialCategory grantAndDenialCategory : grantAndDenialCategories ) { for ( GrantAndDenialWrapper grantAndDenialWrapper : grantAndDenialCategory.grantAndDenialWrappers ) { if ( grantAndDenialWrapper.undoStack.size() == MAX_STACK_SIZE ) { grantAndDenialWrapper.undoStack.remove( grantAndDenialWrapper.undoStack.size() - 1 ); } grantAndDenialWrapper.undoStack.add( 0, grantAndDenialWrapper.activeGrantAndDenial ); grantAndDenialWrapper.redoStack.clear(); undoButton.setEnabled( !grantAndDenialWrapper.undoStack.isEmpty() ); redoButton.setEnabled( !grantAndDenialWrapper.redoStack.isEmpty() ); } } } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/aciitemeditor/src/main/java/org/apache/directory/studio/aciitemeditor/widgets/package-info.java
plugins/aciitemeditor/src/main/java/org/apache/directory/studio/aciitemeditor/widgets/package-info.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. * */ /** * Contains the composed widgets of the ACI item editor dialog. */ package org.apache.directory.studio.aciitemeditor.widgets;
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/aciitemeditor/src/main/java/org/apache/directory/studio/aciitemeditor/widgets/ACIItemUserPermissionsComposite.java
plugins/aciitemeditor/src/main/java/org/apache/directory/studio/aciitemeditor/widgets/ACIItemUserPermissionsComposite.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.aciitemeditor.widgets; import java.util.ArrayList; import java.util.Collection; import java.util.List; import org.apache.directory.api.ldap.aci.GrantAndDenial; import org.apache.directory.api.ldap.aci.ProtectedItem; import org.apache.directory.api.ldap.aci.UserPermission; import org.apache.directory.studio.aciitemeditor.ACIItemValueWithContext; import org.apache.directory.studio.aciitemeditor.Activator; import org.apache.directory.studio.aciitemeditor.dialogs.UserPermissionDialog; import org.apache.directory.studio.aciitemeditor.model.ProtectedItemWrapper; 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.IStructuredSelection; import org.eclipse.jface.viewers.LabelProvider; import org.eclipse.jface.viewers.SelectionChangedEvent; 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.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Table; /** * This composite contains GUI elements to add, edit and delete ACI user permissions. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class ACIItemUserPermissionsComposite extends Composite { /** The context. */ private ACIItemValueWithContext context; /** The inner composite for all the content */ private Composite composite = null; /** The table viewer containing all user classes */ private TableViewer tableViewer = null; /** The add button */ //private Button addButton = null; /** The edit button */ private Button editButton = null; /** The delete button */ private Button deleteButton = null; /** The selected user permissions, also input of the table viewer */ private List<UserPermissionWrapper> userPermissionWrappers = new ArrayList<UserPermissionWrapper>(); /** * UserPermissionWrapper are used as input of the table viewer. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ private class UserPermissionWrapper { /** The user permission bean. */ private UserPermission userPermission; /** * Creates a new instance of UserPermissionWrapper. * * @param userPermission the user permission */ public UserPermissionWrapper( UserPermission userPermission ) { this.userPermission = userPermission; } /** * Returns a user-friedly string, displayed in the table. * * @return the string */ public String toString() { if ( userPermission == null ) { return "<UNKNOWN>"; //$NON-NLS-1$ } else { StringBuilder buffer = new StringBuilder(); if ( ( userPermission.getPrecedence() != null ) && ( userPermission.getPrecedence() > -1 ) ) { buffer.append( '(' ); buffer.append( userPermission.getPrecedence() ); buffer.append( ") " ); } boolean isFirst = true; for ( ProtectedItem item : userPermission.getProtectedItems() ) { if ( isFirst ) { isFirst = false; } else { buffer.append( ',' ); } buffer.append( ProtectedItemWrapper.CLASS_TO_DISPLAY_MAP.get( item.getClass() ) ); } buffer.append( ": " ); isFirst = true; for ( GrantAndDenial gd : userPermission.getGrantsAndDenials() ) { if ( isFirst ) { isFirst = false; } else { buffer.append( ',' ); } if ( gd.isGrant() ) { buffer.append( '+' ); } else { buffer.append( '-' ); } buffer.append( gd.getMicroOperation().getName() ); } String result = buffer.toString(); result = result.replace( '\r', ' ' ); result = result.replace( '\n', ' ' ); if ( buffer.length() > 50 ) { buffer.setLength( 0 ); buffer.append( result.substring( 0, 25 ) ); buffer.append( "..." ); buffer.append( result.substring( result.length() - 25, result.length() ) ); return buffer.toString(); } else { return result; } } } } /** * Creates a new instance of ACIItemUserPermissionsComposite. * * @param parent * @param style */ public ACIItemUserPermissionsComposite( Composite parent, int style ) { super( parent, style ); GridLayout layout = new GridLayout(); layout.horizontalSpacing = 0; layout.verticalSpacing = 0; layout.marginHeight = 0; layout.marginWidth = 0; setLayout( layout ); GridData layoutData = new GridData(); layoutData.horizontalAlignment = GridData.FILL; layoutData.grabExcessHorizontalSpace = true; layoutData.verticalAlignment = GridData.CENTER; setLayoutData( layoutData ); createComposite(); } /** * This method initializes composite * */ private void createComposite() { GridData labelGridData = new GridData(); labelGridData.horizontalSpan = 2; labelGridData.verticalAlignment = GridData.CENTER; labelGridData.grabExcessHorizontalSpace = true; labelGridData.horizontalAlignment = GridData.FILL; GridLayout gridLayout = new GridLayout(); gridLayout.makeColumnsEqualWidth = false; gridLayout.numColumns = 2; GridData gridData = new GridData(); gridData.horizontalAlignment = GridData.FILL; gridData.grabExcessHorizontalSpace = true; gridData.verticalSpan = 1; gridData.verticalAlignment = GridData.BEGINNING; composite = new Composite( this, SWT.NONE ); composite.setLayoutData( gridData ); composite.setLayout( gridLayout ); Label label = new Label( composite, SWT.NONE ); label.setText( Messages.getString( "ACIItemUserPermissionsComposite.descripton" ) ); //$NON-NLS-1$ label.setLayoutData( labelGridData ); createTable(); createButtonComposite(); } /** * This method initializes table and table viewer * */ private void createTable() { GridData tableGridData = new GridData(); tableGridData.grabExcessHorizontalSpace = true; tableGridData.verticalAlignment = GridData.FILL; tableGridData.horizontalAlignment = GridData.FILL; //tableGridData.heightHint = 100; Table table = new Table( composite, SWT.BORDER ); table.setHeaderVisible( false ); table.setLayoutData( tableGridData ); table.setLinesVisible( false ); tableViewer = new TableViewer( table ); tableViewer.setContentProvider( new ArrayContentProvider() ); tableViewer.setLabelProvider( new LabelProvider() ); tableViewer.setInput( userPermissionWrappers ); tableViewer.addSelectionChangedListener( new ISelectionChangedListener() { @Override public void selectionChanged( SelectionChangedEvent event ) { userPermissionSelected(); } } ); tableViewer.addDoubleClickListener( new IDoubleClickListener() { @Override public void doubleClick( DoubleClickEvent event ) { editUserPermission(); } } ); } /** * This method initializes buttons * */ private void createButtonComposite() { GridData deleteButtonGridData = new GridData(); deleteButtonGridData.horizontalAlignment = GridData.FILL; deleteButtonGridData.grabExcessHorizontalSpace = false; deleteButtonGridData.verticalAlignment = GridData.BEGINNING; deleteButtonGridData.widthHint = Activator.getButtonWidth( this ); GridData editButtonGridData = new GridData(); editButtonGridData.horizontalAlignment = GridData.FILL; editButtonGridData.grabExcessHorizontalSpace = false; editButtonGridData.verticalAlignment = GridData.BEGINNING; editButtonGridData.widthHint = Activator.getButtonWidth( this ); GridData addButtonGridData = new GridData(); addButtonGridData.horizontalAlignment = GridData.FILL; addButtonGridData.grabExcessHorizontalSpace = false; addButtonGridData.verticalAlignment = GridData.BEGINNING; addButtonGridData.widthHint = Activator.getButtonWidth( this ); GridLayout gridLayout = new GridLayout(); gridLayout.marginWidth = 0; gridLayout.marginHeight = 0; GridData gridData = new GridData(); gridData.horizontalAlignment = GridData.CENTER; gridData.grabExcessHorizontalSpace = false; gridData.grabExcessVerticalSpace = false; gridData.verticalAlignment = GridData.FILL; Composite buttonComposite = new Composite( composite, SWT.NONE ); buttonComposite.setLayoutData( gridData ); buttonComposite.setLayout( gridLayout ); Button addButton = new Button( buttonComposite, SWT.NONE ); addButton.setText( Messages.getString( "ACIItemUserPermissionsComposite.add.button" ) ); //$NON-NLS-1$ addButton.setLayoutData( addButtonGridData ); addButton.addSelectionListener( new SelectionAdapter() { @Override public void widgetSelected( SelectionEvent event ) { addUserPermission(); } } ); editButton = new Button( buttonComposite, SWT.NONE ); editButton.setText( Messages.getString( "ACIItemUserPermissionsComposite.edit.button" ) ); //$NON-NLS-1$ editButton.setLayoutData( editButtonGridData ); editButton.addSelectionListener( new SelectionAdapter() { @Override public void widgetSelected( SelectionEvent event ) { editUserPermission(); } } ); editButton.setEnabled( false ); deleteButton = new Button( buttonComposite, SWT.NONE ); deleteButton.setText( Messages.getString( "ACIItemUserPermissionsComposite.delete.button" ) ); //$NON-NLS-1$ deleteButton.setLayoutData( deleteButtonGridData ); deleteButton.addSelectionListener( new SelectionAdapter() { @Override public void widgetSelected( SelectionEvent event ) { deleteUserPermission(); } } ); deleteButton.setEnabled( false ); } /** * Shows or hides this composite. * * @param visible true if visible */ public void setVisible( boolean visible ) { super.setVisible( visible ); if ( visible ) { ( ( GridData ) getLayoutData() ).heightHint = -1; } else { ( ( GridData ) getLayoutData() ).heightHint = 0; } } /** * Sets the context. * * @param context the context */ public void setContext( ACIItemValueWithContext context ) { this.context = context; } /** * Sets the user permissions. * * @param userPermissions */ public void setUserPermissions( Collection<UserPermission> userPermissions ) { userPermissionWrappers.clear(); for ( UserPermission userPermission : userPermissions ) { UserPermissionWrapper userPermissionWrapper = new UserPermissionWrapper( userPermission ); userPermissionWrappers.add( userPermissionWrapper ); } tableViewer.refresh(); } /** * Returns the user permissions as selected by the user. * * @return the user permissions */ public Collection<UserPermission> getUserPermissions() { Collection<UserPermission> userPermissions = new ArrayList<UserPermission>(); for ( UserPermissionWrapper userPermissionWrapper : userPermissionWrappers ) { userPermissions.add( userPermissionWrapper.userPermission ); } return userPermissions; } /** * * @return the user permission that is selected in the table viewer, or null. */ private UserPermissionWrapper getSelectedUserPermissionWrapper() { IStructuredSelection selection = ( IStructuredSelection ) tableViewer.getSelection(); if ( !selection.isEmpty() ) { Object element = selection.getFirstElement(); if ( element instanceof UserPermissionWrapper ) { return ( UserPermissionWrapper ) element; } } return null; } /** * Opens the UserPermissionDialog and adds the composed * user permission to the list. */ private void addUserPermission() { UserPermissionDialog dialog = new UserPermissionDialog( getShell(), null, context ); if ( ( dialog.open() == UserPermissionDialog.OK ) && ( dialog.getUserPermission() != null ) ) { UserPermissionWrapper userPermissionWrapper = new UserPermissionWrapper( dialog.getUserPermission() ); userPermissionWrappers.add( userPermissionWrapper ); tableViewer.refresh(); } } /** * Opens the UserPermissionDialog with the currently selected * user permission and puts the modified user permission into the list. */ private void editUserPermission() { UserPermissionWrapper oldUserPermissionWrapper = getSelectedUserPermissionWrapper(); if ( oldUserPermissionWrapper != null ) { UserPermissionDialog dialog = new UserPermissionDialog( getShell(), oldUserPermissionWrapper.userPermission, context ); if ( dialog.open() == UserPermissionDialog.OK ) { oldUserPermissionWrapper.userPermission = dialog.getUserPermission(); tableViewer.refresh(); } } } /** * Deletes the currently selected user permission from list. */ private void deleteUserPermission() { UserPermissionWrapper userPermissionWrapper = getSelectedUserPermissionWrapper(); if ( userPermissionWrapper != null ) { userPermissionWrappers.remove( userPermissionWrapper ); tableViewer.refresh(); } } /** * Called when an user permission is selected in table viewer. * Updates the enabled/disabled state of the buttons. */ private void userPermissionSelected() { UserPermissionWrapper userPermissionWrapper = getSelectedUserPermissionWrapper(); if ( userPermissionWrapper == null ) { editButton.setEnabled( false ); deleteButton.setEnabled( false ); } else { editButton.setEnabled( true ); deleteButton.setEnabled( 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/aciitemeditor/src/main/java/org/apache/directory/studio/aciitemeditor/widgets/Messages.java
plugins/aciitemeditor/src/main/java/org/apache/directory/studio/aciitemeditor/widgets/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.aciitemeditor.widgets; 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 final 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/aciitemeditor/src/main/java/org/apache/directory/studio/aciitemeditor/widgets/ACIItemVisualEditorComposite.java
plugins/aciitemeditor/src/main/java/org/apache/directory/studio/aciitemeditor/widgets/ACIItemVisualEditorComposite.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.aciitemeditor.widgets; import java.text.ParseException; import java.util.Collection; import org.apache.directory.api.ldap.aci.ACIItem; import org.apache.directory.api.ldap.aci.ACIItemParser; import org.apache.directory.api.ldap.aci.ItemFirstACIItem; import org.apache.directory.api.ldap.aci.ItemPermission; import org.apache.directory.api.ldap.aci.ProtectedItem; import org.apache.directory.api.ldap.aci.UserClass; import org.apache.directory.api.ldap.aci.UserFirstACIItem; import org.apache.directory.api.ldap.aci.UserPermission; import org.apache.directory.api.ldap.model.constants.AuthenticationLevel; import org.apache.directory.studio.aciitemeditor.ACIItemValueWithContext; import org.eclipse.swt.SWT; import org.eclipse.swt.custom.ScrolledComposite; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Composite; /** * This is the main widget of the ACI item visual editor. It manages * the lifecyle of all other ACI item widgets. In particular it * shows/hides the userFirst and itemFirst widgets depending on * the user's selection. * <p> * It extends ScrolledComposite. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class ACIItemVisualEditorComposite extends ScrolledComposite implements WidgetModifyListener { /** The inner composite for all the content */ private Composite composite = null; /** The general composite contains id-tag, precedence, auth-level, userFirst/itemFirst */ private ACIItemGeneralComposite generalComposite = null; /** The user classes composite used for userFirst selection */ private ACIItemUserClassesComposite userFirstUserClassesComposite = null; /** The user permission composite used for userFirst selection */ private ACIItemUserPermissionsComposite userFirstUserPermissionsComposite = null; /** The protected items composite used for itemFirst selection */ private ACIItemProtectedItemsComposite itemFirstProtectedItemsComposite = null; /** The item permission composite used for itemFirst selection */ private ACIItemItemPermissionsComposite itemFirstItemPermissionsComposite = null; /** * Creates a new instance of ACIItemComposite. * * @param parent * @param style */ public ACIItemVisualEditorComposite( Composite parent, int style ) { super( parent, style | SWT.H_SCROLL | SWT.V_SCROLL ); setExpandHorizontal( true ); setExpandVertical( true ); createComposite(); setContent( composite ); setMinSize( composite.computeSize( SWT.DEFAULT, SWT.DEFAULT ) ); } /** * This method initializes the inner composite with all contained widgets. * */ private void createComposite() { composite = new Composite( this, SWT.NONE ); composite.setLayout( new GridLayout() ); composite.setLayoutData( new GridData( SWT.FILL, SWT.FILL, true, true ) ); generalComposite = new ACIItemGeneralComposite( composite, SWT.NONE ); generalComposite.addWidgetModifyListener( this ); userFirstUserClassesComposite = new ACIItemUserClassesComposite( composite, SWT.NONE ); userFirstUserPermissionsComposite = new ACIItemUserPermissionsComposite( composite, SWT.NONE ); itemFirstProtectedItemsComposite = new ACIItemProtectedItemsComposite( composite, SWT.NONE ); itemFirstItemPermissionsComposite = new ACIItemItemPermissionsComposite( composite, SWT.NONE ); widgetModified( null ); } /** * This method is called from the contained ACIItemXXXComposites * when they are modified. * * @param event the event */ public void widgetModified( WidgetModifyEvent event ) { // switch userFirst / itemFirst if ( generalComposite.isItemFirst() && !generalComposite.isUserFirst() && !itemFirstProtectedItemsComposite.isVisible() ) { userFirstUserClassesComposite.setVisible( false ); userFirstUserPermissionsComposite.setVisible( false ); itemFirstProtectedItemsComposite.setVisible( true ); itemFirstItemPermissionsComposite.setVisible( true ); setMinSize( composite.computeSize( SWT.DEFAULT, SWT.DEFAULT ) ); layout( true, true ); } else if ( generalComposite.isUserFirst() && !generalComposite.isItemFirst() && !userFirstUserClassesComposite.isVisible() ) { userFirstUserClassesComposite.setVisible( true ); userFirstUserPermissionsComposite.setVisible( true ); itemFirstProtectedItemsComposite.setVisible( false ); itemFirstItemPermissionsComposite.setVisible( false ); setMinSize( composite.computeSize( SWT.DEFAULT, SWT.DEFAULT ) ); layout( true, true ); } else if ( !generalComposite.isItemFirst() && !generalComposite.isUserFirst() ) { userFirstUserClassesComposite.setVisible( false ); userFirstUserPermissionsComposite.setVisible( false ); itemFirstProtectedItemsComposite.setVisible( false ); itemFirstItemPermissionsComposite.setVisible( false ); setMinSize( composite.computeSize( SWT.DEFAULT, SWT.DEFAULT ) ); layout( true, true ); } } /** * Sets the input. The given ACI Item string is parsed and * populated to the GUI elements. * * * @param input The string representation of the ACI item * @throws ParseException if the syntax is invalid */ public void setInput( String input ) throws ParseException { ACIItemParser parser = new ACIItemParser( null ); ACIItem aciItem = parser.parse( input ); if ( aciItem != null ) { generalComposite.setIdentificationTag( aciItem.getIdentificationTag() ); generalComposite.setPrecedence( aciItem.getPrecedence() ); generalComposite.setAuthenticationLevel( aciItem.getAuthenticationLevel() ); if ( aciItem instanceof ItemFirstACIItem ) { ItemFirstACIItem itemFirstACI = ( ItemFirstACIItem ) aciItem; generalComposite.setItemFirst(); itemFirstProtectedItemsComposite.setProtectedItems( itemFirstACI.getProtectedItems() ); itemFirstItemPermissionsComposite.setItemPermissions( itemFirstACI.getItemPermissions() ); } else if ( aciItem instanceof UserFirstACIItem ) { UserFirstACIItem userFirstACI = ( UserFirstACIItem ) aciItem; generalComposite.setUserFirst(); userFirstUserClassesComposite.setUserClasses( userFirstACI.getUserClasses() ); userFirstUserPermissionsComposite.setUserPermissions( userFirstACI.getUserPermission() ); } } // force userFirst/itemFirst switch widgetModified( null ); } /** * Returns the string representation of the ACI item as defined in GUI. * * * @return the string representation of the ACI item * @throws ParseException if the syntax is invalid */ public String getInput() throws ParseException { String identificationTag = generalComposite.getIdentificationTag(); int precedence = generalComposite.getPrecedence(); AuthenticationLevel authenticationLevel = generalComposite.getAuthenticationLevel(); ACIItem aciItem = null; if ( generalComposite.isUserFirst() ) { Collection<UserClass> userClasses = userFirstUserClassesComposite.getUserClasses(); Collection<UserPermission> userPermissions = userFirstUserPermissionsComposite.getUserPermissions(); aciItem = new UserFirstACIItem( identificationTag, precedence, authenticationLevel, userClasses, userPermissions ); } else if ( generalComposite.isItemFirst() ) { Collection<ProtectedItem> protectedItems = itemFirstProtectedItemsComposite.getProtectedItems(); Collection<ItemPermission> itemPermissions = itemFirstItemPermissionsComposite.getItemPermissions(); aciItem = new ItemFirstACIItem( identificationTag, precedence, authenticationLevel, protectedItems, itemPermissions ); } else { aciItem = null; } String aci = ""; //$NON-NLS-1$ if ( aciItem != null ) { aci = aciItem.toString(); } return aci; } /** * Sets the context. * * @param context the context */ public void setContext( ACIItemValueWithContext context ) { itemFirstProtectedItemsComposite.setContext( context ); itemFirstItemPermissionsComposite.setContext( context ); userFirstUserClassesComposite.setContext( context ); userFirstUserPermissionsComposite.setContext( context ); } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/aciitemeditor/src/main/java/org/apache/directory/studio/aciitemeditor/widgets/WidgetModifyEvent.java
plugins/aciitemeditor/src/main/java/org/apache/directory/studio/aciitemeditor/widgets/WidgetModifyEvent.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.aciitemeditor.widgets; import java.util.EventObject; /** * A WidgetModifyEvent contains details of the widget modification. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class WidgetModifyEvent extends EventObject { /** Serialization UUID */ private static final long serialVersionUID = 2421335730580648878L; /** * Creates a new instance of WidgetModifyEvent. * * @param source the object on which the event initially occurred */ public WidgetModifyEvent( Object source ) { super( source ); } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/aciitemeditor/src/main/java/org/apache/directory/studio/aciitemeditor/widgets/ACIItemItemPermissionsComposite.java
plugins/aciitemeditor/src/main/java/org/apache/directory/studio/aciitemeditor/widgets/ACIItemItemPermissionsComposite.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.aciitemeditor.widgets; import java.util.ArrayList; import java.util.Collection; import java.util.List; import org.apache.directory.api.ldap.aci.GrantAndDenial; import org.apache.directory.api.ldap.aci.ItemPermission; import org.apache.directory.api.ldap.aci.UserClass; import org.apache.directory.studio.aciitemeditor.ACIItemValueWithContext; import org.apache.directory.studio.aciitemeditor.Activator; import org.apache.directory.studio.aciitemeditor.dialogs.ItemPermissionDialog; import org.apache.directory.studio.aciitemeditor.model.UserClassWrapper; 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.IStructuredSelection; import org.eclipse.jface.viewers.LabelProvider; import org.eclipse.jface.viewers.SelectionChangedEvent; 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.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Table; /** * This composite contains GUI elements to add, edit and delete ACI item permissions. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class ACIItemItemPermissionsComposite extends Composite { /** The context. */ private ACIItemValueWithContext context; /** The inner composite for all the content */ private Composite composite = null; /** The table viewer containing all item classes */ private TableViewer tableViewer = null; /** The edit button */ private Button editButton = null; /** The delete button */ private Button deleteButton = null; /** The selected item permissions, input of the table viewer */ private List<ItemPermissionWrapper> itemPermissionWrappers = new ArrayList<ItemPermissionWrapper>(); /** * ItemPermissionWrappers are used as input of the table viewer. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ private class ItemPermissionWrapper { /** The item permission bean. */ private ItemPermission itemPermission; /** * Creates a new instance of ItemPermissionWrapper. * * @param itemClassClass */ private ItemPermissionWrapper( ItemPermission itemPermission ) { this.itemPermission = itemPermission; } /** * Returns a user-friedly string, displayed in the table. * * @return the string */ public String toString() { if ( itemPermission == null ) { return "<UNKNOWN>"; //$NON-NLS-1$ } else { StringBuilder buffer = new StringBuilder(); if ( ( itemPermission.getPrecedence() != null ) && ( itemPermission.getPrecedence() > -1 ) ) { buffer.append( '(' ); buffer.append( itemPermission.getPrecedence() ); buffer.append( ") " ); } boolean isFirst = true; for ( UserClass userClass : itemPermission.getUserClasses() ) { if ( isFirst ) { isFirst = false; } else { buffer.append( ',' ); } String s = UserClassWrapper.CLASS_TO_DISPLAY_MAP.get( userClass.getClass() ); buffer.append( s ); } buffer.append( ": " ); isFirst = true; for ( GrantAndDenial grantAndDenial : itemPermission.getGrantsAndDenials() ) { if ( isFirst ) { isFirst = false; } else { buffer.append( ',' ); } if ( grantAndDenial.isGrant() ) { buffer.append( '+' ); } else { buffer.append( '-' ); } buffer.append( grantAndDenial.getMicroOperation().getName() ); } String s = buffer.toString(); s = s.replace( '\r', ' ' ); s = s.replace( '\n', ' ' ); if ( s.length() > 50 ) { String temp = s; s = temp.substring( 0, 25 ); s = s + "..."; //$NON-NLS-1$ s = s + temp.substring( temp.length() - 25, temp.length() ); } return s; } } } /** * * Creates a new instance of ACIItemItemPermissionsComposite. * * @param parent * @param style */ public ACIItemItemPermissionsComposite( Composite parent, int style ) { super( parent, style ); GridLayout layout = new GridLayout(); layout.horizontalSpacing = 0; layout.verticalSpacing = 0; layout.marginHeight = 0; layout.marginWidth = 0; setLayout( layout ); GridData layoutData = new GridData(); layoutData.horizontalAlignment = GridData.FILL; layoutData.grabExcessHorizontalSpace = true; layoutData.verticalAlignment = GridData.CENTER; setLayoutData( layoutData ); createComposite(); } /** * This method initializes composite * */ private void createComposite() { GridData labelGridData = new GridData(); labelGridData.horizontalSpan = 2; labelGridData.verticalAlignment = GridData.CENTER; labelGridData.grabExcessHorizontalSpace = true; labelGridData.horizontalAlignment = GridData.FILL; GridLayout gridLayout = new GridLayout(); gridLayout.makeColumnsEqualWidth = false; gridLayout.numColumns = 2; GridData gridData = new GridData(); gridData.horizontalAlignment = GridData.FILL; gridData.grabExcessHorizontalSpace = true; gridData.verticalSpan = 1; gridData.verticalAlignment = GridData.BEGINNING; composite = new Composite( this, SWT.NONE ); composite.setLayoutData( gridData ); composite.setLayout( gridLayout ); Label label = new Label( composite, SWT.NONE ); label.setText( Messages.getString( "ACIItemItemPermissionsComposite.description" ) ); //$NON-NLS-1$ label.setLayoutData( labelGridData ); createTable(); createButtonComposite(); } /** * This method initializes table and table viewer * */ private void createTable() { GridData tableGridData = new GridData(); tableGridData.grabExcessHorizontalSpace = true; tableGridData.verticalAlignment = GridData.FILL; tableGridData.horizontalAlignment = GridData.FILL; //tableGridData.heightHint = 100; Table table = new Table( composite, SWT.BORDER ); table.setHeaderVisible( false ); table.setLayoutData( tableGridData ); table.setLinesVisible( false ); tableViewer = new TableViewer( table ); tableViewer.setContentProvider( new ArrayContentProvider() ); tableViewer.setLabelProvider( new LabelProvider() ); tableViewer.setInput( itemPermissionWrappers ); tableViewer.addSelectionChangedListener( new ISelectionChangedListener() { public void selectionChanged( SelectionChangedEvent event ) { itemPermissionSelected(); } } ); tableViewer.addDoubleClickListener( new IDoubleClickListener() { public void doubleClick( DoubleClickEvent event ) { editItemPermission(); } } ); } /** * This method initializes buttons * */ private void createButtonComposite() { GridData deleteButtonGridData = new GridData(); deleteButtonGridData.horizontalAlignment = GridData.FILL; deleteButtonGridData.grabExcessHorizontalSpace = false; deleteButtonGridData.verticalAlignment = GridData.BEGINNING; deleteButtonGridData.widthHint = Activator.getButtonWidth( this ); GridData editButtonGridData = new GridData(); editButtonGridData.horizontalAlignment = GridData.FILL; editButtonGridData.grabExcessHorizontalSpace = false; editButtonGridData.verticalAlignment = GridData.BEGINNING; editButtonGridData.widthHint = Activator.getButtonWidth( this ); GridData addButtonGridData = new GridData(); addButtonGridData.horizontalAlignment = GridData.FILL; addButtonGridData.grabExcessHorizontalSpace = false; addButtonGridData.verticalAlignment = GridData.BEGINNING; addButtonGridData.widthHint = Activator.getButtonWidth( this ); GridLayout gridLayout = new GridLayout(); gridLayout.marginWidth = 0; gridLayout.marginHeight = 0; GridData gridData = new GridData(); gridData.horizontalAlignment = GridData.CENTER; gridData.grabExcessHorizontalSpace = false; gridData.grabExcessVerticalSpace = false; gridData.verticalAlignment = GridData.FILL; Composite buttonComposite = new Composite( composite, SWT.NONE ); buttonComposite.setLayoutData( gridData ); buttonComposite.setLayout( gridLayout ); Button addButton = new Button( buttonComposite, SWT.NONE ); addButton.setText( Messages.getString( "ACIItemItemPermissionsComposite.add.button" ) ); //$NON-NLS-1$ addButton.setLayoutData( addButtonGridData ); addButton.addSelectionListener( new SelectionAdapter() { public void widgetSelected( SelectionEvent e ) { addItemPermission(); } } ); editButton = new Button( buttonComposite, SWT.NONE ); editButton.setText( Messages.getString( "ACIItemItemPermissionsComposite.edit.button" ) ); //$NON-NLS-1$ editButton.setLayoutData( editButtonGridData ); editButton.addSelectionListener( new SelectionAdapter() { public void widgetSelected( SelectionEvent e ) { editItemPermission(); } } ); editButton.setEnabled( false ); deleteButton = new Button( buttonComposite, SWT.NONE ); deleteButton.setText( Messages.getString( "ACIItemItemPermissionsComposite.delete.button" ) ); //$NON-NLS-1$ deleteButton.setLayoutData( deleteButtonGridData ); deleteButton.addSelectionListener( new SelectionAdapter() { public void widgetSelected( SelectionEvent e ) { deleteItemPermission(); } } ); deleteButton.setEnabled( false ); } /** * Shows or hides this composite. * * @param visible true if visible */ public void setVisible( boolean visible ) { super.setVisible( visible ); ( ( GridData ) getLayoutData() ).heightHint = visible ? -1 : 0; } /** * Sets the context. * * @param context the context */ public void setContext( ACIItemValueWithContext context ) { this.context = context; } /** * Sets the item permissions. * * @param itemPermissions */ public void setItemPermissions( Collection<ItemPermission> itemPermissions ) { itemPermissionWrappers.clear(); for ( ItemPermission itemPermission : itemPermissions ) { ItemPermissionWrapper itemPermissionWrapper = new ItemPermissionWrapper( itemPermission ); itemPermissionWrappers.add( itemPermissionWrapper ); } tableViewer.refresh(); } /** * Returns the item permissions as selected by the user. * * @return the item permissions */ public Collection<ItemPermission> getItemPermissions() { Collection<ItemPermission> itemPermissions = new ArrayList<ItemPermission>(); for ( ItemPermissionWrapper itemPermissionWrapper : itemPermissionWrappers ) { itemPermissions.add( itemPermissionWrapper.itemPermission ); } return itemPermissions; } /** * * @return the item permission that is selected in the table viewer, or null. */ private ItemPermissionWrapper getSelectedItemPermissionWrapper() { ItemPermissionWrapper itemPermissionWrapper = null; IStructuredSelection selection = ( IStructuredSelection ) tableViewer.getSelection(); if ( !selection.isEmpty() ) { Object element = selection.getFirstElement(); if ( element instanceof ItemPermissionWrapper ) { itemPermissionWrapper = ( ItemPermissionWrapper ) element; } } return itemPermissionWrapper; } /** * Opens the ItemPermissionDialog and adds the composed * item permission to the list. */ private void addItemPermission() { ItemPermissionDialog dialog = new ItemPermissionDialog( getShell(), null, context ); if ( dialog.open() == ItemPermissionDialog.OK && dialog.getItemPermission() != null ) { ItemPermissionWrapper itemPermissionWrapper = new ItemPermissionWrapper( dialog.getItemPermission() ); itemPermissionWrappers.add( itemPermissionWrapper ); tableViewer.refresh(); } } /** * Opens the ItemPermissionDialog with the currently selected * item permission and puts the modified item permission into the list. */ private void editItemPermission() { ItemPermissionWrapper oldItemPermissionWrapper = getSelectedItemPermissionWrapper(); if ( oldItemPermissionWrapper != null ) { ItemPermissionDialog dialog = new ItemPermissionDialog( getShell(), oldItemPermissionWrapper.itemPermission, context ); if ( dialog.open() == ItemPermissionDialog.OK ) { oldItemPermissionWrapper.itemPermission = dialog.getItemPermission(); tableViewer.refresh(); } } } /** * Deletes the currently selected item permission from list. */ private void deleteItemPermission() { ItemPermissionWrapper itemPermissionWrapper = getSelectedItemPermissionWrapper(); if ( itemPermissionWrapper != null ) { itemPermissionWrappers.remove( itemPermissionWrapper ); tableViewer.refresh(); } } /** * Called when an item permission is selected in table viewer. * Updates the enabled/disabled state of the buttons. */ private void itemPermissionSelected() { ItemPermissionWrapper itemPermissionWrapper = getSelectedItemPermissionWrapper(); if ( itemPermissionWrapper == null ) { editButton.setEnabled( false ); deleteButton.setEnabled( false ); } else { editButton.setEnabled( true ); deleteButton.setEnabled( 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/aciitemeditor/src/main/java/org/apache/directory/studio/aciitemeditor/widgets/ACIItemTabFolderComposite.java
plugins/aciitemeditor/src/main/java/org/apache/directory/studio/aciitemeditor/widgets/ACIItemTabFolderComposite.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.aciitemeditor.widgets; import java.text.ParseException; import org.apache.directory.studio.aciitemeditor.ACIITemConstants; import org.apache.directory.studio.aciitemeditor.ACIItemValueWithContext; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Status; import org.eclipse.jface.dialogs.ErrorDialog; import org.eclipse.swt.SWT; 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.Composite; import org.eclipse.swt.widgets.TabFolder; import org.eclipse.swt.widgets.TabItem; /** * This composite contains the tabs with visual and source editor. * It also manages the synchronization between these two tabs. * * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class ACIItemTabFolderComposite extends Composite { /** The index of the visual tab */ public static final int VISUAL_TAB_INDEX = 0; /** The index of the source tab */ public static final int SOURCE_TAB_INDEX = 1; /** The tab folder */ private TabFolder tabFolder; /** The visual editor composite */ private ACIItemVisualEditorComposite visualComposite; /** The source editor composite */ private ACIItemSourceEditorComposite sourceComposite; /** * Creates a new instance of TabFolderComposite. * * @param parent * @param style */ public ACIItemTabFolderComposite( Composite parent, int style ) { super( parent, style ); GridLayout layout = new GridLayout(); layout.marginWidth = layout.marginHeight = 0; setLayout( layout ); setLayoutData( new GridData( SWT.FILL, SWT.FILL, true, true ) ); createTabFolder(); createVisualTab(); createSourceTab(); initListeners(); } /** * Initializes the listeners. * */ private void initListeners() { tabFolder.addSelectionListener( new SelectionAdapter() { @Override public void widgetSelected( SelectionEvent event ) { tabSelected(); } } ); } /** * Creates the source tab and configures the source editor. * */ private void createSourceTab() { // create inner container Composite sourceContainer = new Composite( tabFolder, SWT.NONE ); GridLayout layout = new GridLayout(); layout.marginWidth = layout.marginHeight = 0; sourceContainer.setLayout( layout ); sourceContainer.setLayoutData( new GridData( SWT.FILL, SWT.FILL, true, true ) ); // create source editor sourceComposite = new ACIItemSourceEditorComposite( sourceContainer, SWT.NONE ); sourceComposite.setLayoutData( new GridData( SWT.FILL, SWT.FILL, true, true ) ); // create tab TabItem sourceTab = new TabItem( tabFolder, SWT.NONE, SOURCE_TAB_INDEX ); sourceTab.setText( Messages.getString( "ACIItemTabFolderComposite.source.tab" ) ); //$NON-NLS-1$ sourceTab.setControl( sourceContainer ); } /** * Creates the visual tab and the GUI editor. * */ private void createVisualTab() { // create inner container Composite visualContainer = new Composite( tabFolder, SWT.NONE ); visualContainer.setLayout( new GridLayout() ); visualContainer.setLayoutData( new GridData( SWT.FILL, SWT.FILL, true, true ) ); // create the visual ACIItem composite visualComposite = new ACIItemVisualEditorComposite( visualContainer, SWT.NONE ); visualComposite.setLayoutData( new GridData( SWT.FILL, SWT.FILL, true, true ) ); // create tab TabItem visualTab = new TabItem( tabFolder, SWT.NONE, VISUAL_TAB_INDEX ); visualTab.setText( Messages.getString( "ACIItemTabFolderComposite.visual.tab" ) ); //$NON-NLS-1$ visualTab.setControl( visualContainer ); } /** * Creates the tab folder and the listeners. * */ private void createTabFolder() { tabFolder = new TabFolder( this, SWT.TOP ); tabFolder.setLayoutData( new GridData( SWT.FILL, SWT.FILL, true, true ) ); } /** * Called, when a tab is selected. This method manages the synchronization * between visual and source editor. */ private void tabSelected() { int index = tabFolder.getSelectionIndex(); if ( index == SOURCE_TAB_INDEX ) { // switched to source tab: serialize visual and set to source // on parse error: print message and return to visual tab try { String input = visualComposite.getInput(); sourceComposite.setInput( input ); } catch ( ParseException pe ) { IStatus status = new Status( IStatus.ERROR, ACIITemConstants.PLUGIN_ID, 1, Messages .getString( "ACIItemTabFolderComposite.error.onVisualEditor" ), pe ); //$NON-NLS-1$ ErrorDialog.openError( getShell(), Messages.getString( "ACIItemTabFolderComposite.error.title" ), null, status ); //$NON-NLS-1$ tabFolder.setSelection( VISUAL_TAB_INDEX ); } } else if ( index == VISUAL_TAB_INDEX ) { // switched to visual tab: parse source and populate to visual // on parse error: print message and return to source tab try { String input = sourceComposite.getInput(); visualComposite.setInput( input ); } catch ( ParseException pe ) { IStatus status = new Status( IStatus.ERROR, ACIITemConstants.PLUGIN_ID, 1, Messages .getString( "ACIItemTabFolderComposite.error.onSourceEditor" ), pe ); //$NON-NLS-1$ ErrorDialog.openError( getShell(), Messages.getString( "ACIItemTabFolderComposite.error.title" ), null, status ); //$NON-NLS-1$ tabFolder.setSelection( SOURCE_TAB_INDEX ); } } } /** * Sets the input to both the source editor and to the visual editor. * If the syntax is invalid the source editor is activated. * * @param input The string representation of the ACI item */ public void setInput( String input ) { // set input to source editor sourceComposite.forceSetInput( input ); // set input to visual editor, on parse error switch to source editor try { visualComposite.setInput( input ); } catch ( ParseException pe ) { IStatus status = new Status( IStatus.ERROR, ACIITemConstants.PLUGIN_ID, 1, Messages .getString( "ACIItemTabFolderComposite.error.onInput" ), pe ); //$NON-NLS-1$ ErrorDialog.openError( getShell(), Messages.getString( "ACIItemTabFolderComposite.error.title" ), null, status ); //$NON-NLS-1$ tabFolder.setSelection( SOURCE_TAB_INDEX ); } } /** * Returns the string representation of the ACI item. * A syntax check is performed before returning the input, an * invalid syntax causes a ParseException. * * @return the valid string representation of the ACI item * @throws ParseException it the syntax check fails. */ public String getInput() throws ParseException { int index = tabFolder.getSelectionIndex(); if ( index == VISUAL_TAB_INDEX ) { String input = visualComposite.getInput(); return input; } else { String input = sourceComposite.getInput(); return input; } } /** * Sets the context. * * @param context the context */ public void setContext( ACIItemValueWithContext context ) { sourceComposite.setContext( context ); visualComposite.setContext( context ); } /** * Formats the content. */ public void format() { sourceComposite.format(); //visualComposite.format(); } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/aciitemeditor/src/main/java/org/apache/directory/studio/aciitemeditor/widgets/WidgetModifyListener.java
plugins/aciitemeditor/src/main/java/org/apache/directory/studio/aciitemeditor/widgets/WidgetModifyListener.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.aciitemeditor.widgets; /** * A widget modify listeners gets informed if a widget was modified. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public interface WidgetModifyListener { /** * Informs this listener that a widget was modified * * @param event */ void widgetModified( WidgetModifyEvent event ); }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/aciitemeditor/src/main/java/org/apache/directory/studio/aciitemeditor/dialogs/package-info.java
plugins/aciitemeditor/src/main/java/org/apache/directory/studio/aciitemeditor/dialogs/package-info.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. * */ /** * Contains the dialogs of the ACI item editor. */ package org.apache.directory.studio.aciitemeditor.dialogs;
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/aciitemeditor/src/main/java/org/apache/directory/studio/aciitemeditor/dialogs/Messages.java
plugins/aciitemeditor/src/main/java/org/apache/directory/studio/aciitemeditor/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.aciitemeditor.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 final 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/aciitemeditor/src/main/java/org/apache/directory/studio/aciitemeditor/dialogs/UserPermissionDialog.java
plugins/aciitemeditor/src/main/java/org/apache/directory/studio/aciitemeditor/dialogs/UserPermissionDialog.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.aciitemeditor.dialogs; import java.util.Collection; import org.apache.directory.api.ldap.aci.GrantAndDenial; import org.apache.directory.api.ldap.aci.ProtectedItem; import org.apache.directory.api.ldap.aci.UserPermission; import org.apache.directory.studio.aciitemeditor.ACIItemValueWithContext; import org.apache.directory.studio.aciitemeditor.Activator; import org.apache.directory.studio.aciitemeditor.widgets.ACIItemGrantsAndDenialsComposite; import org.apache.directory.studio.aciitemeditor.widgets.ACIItemProtectedItemsComposite; import org.eclipse.jface.dialogs.Dialog; import org.eclipse.jface.dialogs.IDialogConstants; import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.swt.SWT; 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.Composite; import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.widgets.Spinner; /** * A dialog to compose user permissions. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class UserPermissionDialog extends Dialog { /** The context */ private ACIItemValueWithContext context; /** The initial value, passed by the constructor */ private UserPermission initialUserPermission; /** The resulting value returned by getUserPermission() */ private UserPermission returnUserPermission; /** The precedence checkbox to enable/disable spinner */ private Button precedenceCheckbox = null; /** The precedence spinner */ private Spinner precedenceSpinner = null; /** The widget with protected items table */ private ACIItemProtectedItemsComposite protectedItemsComposite; /** The widget with grants and denials table */ private ACIItemGrantsAndDenialsComposite grantsAndDenialsComposite; /** * Creates a new instance of UserPermissionDialog. * * @param parentShell the shell * @param initialUserPermission the initial user permission * @param context the context */ public UserPermissionDialog( Shell parentShell, UserPermission initialUserPermission, ACIItemValueWithContext context ) { super( parentShell ); super.setShellStyle( super.getShellStyle() | SWT.RESIZE ); this.initialUserPermission = initialUserPermission; this.context = context; this.returnUserPermission = null; } /** * Sets the dialog image and text. * * {@inheritDoc} */ protected void configureShell( Shell shell ) { super.configureShell( shell ); shell.setText( Messages.getString( "UserPermissionDialog.dialog.text" ) ); //$NON-NLS-1$ shell.setImage( Activator.getDefault().getImage( Messages.getString( "UserPermissionDialog.dialog.icon" ) ) ); //$NON-NLS-1$ } /** * Reimplementation: Checks for valid syntax and sets the return value. */ protected void okPressed() { try { Integer precedence = precedenceCheckbox.getSelection() ? precedenceSpinner.getSelection() : null; Collection<ProtectedItem> protectedItems = protectedItemsComposite.getProtectedItems(); Collection<GrantAndDenial> grantsAndDenials = grantsAndDenialsComposite.getGrantsAndDenials(); returnUserPermission = new UserPermission( precedence, grantsAndDenials, protectedItems ); super.okPressed(); } catch ( Exception e ) { MessageDialog.openError( getShell(), Messages .getString( "UserPermissionDialog.error.invalidUserPermission" ), e.getMessage() ); //$NON-NLS-1$ } } /** * {@inheritDoc} */ protected Control createDialogArea( Composite parent ) { Composite composite = ( Composite ) super.createDialogArea( parent ); GridData gd = new GridData( GridData.FILL_BOTH ); gd.widthHint = convertHorizontalDLUsToPixels( IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH ); gd.heightHint = convertVerticalDLUsToPixels( IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH ) * 4 / 3; composite.setLayoutData( gd ); // precedence Composite spinnerComposite = new Composite( composite, SWT.NONE ); spinnerComposite.setLayout( new GridLayout( 2, false ) ); spinnerComposite.setLayoutData( new GridData() ); precedenceCheckbox = new Button( spinnerComposite, SWT.CHECK ); precedenceCheckbox.setText( Messages.getString( "UserPermissionDialog.precedence.label" ) ); //$NON-NLS-1$ precedenceCheckbox.addSelectionListener( new SelectionAdapter() { public void widgetSelected( SelectionEvent e ) { precedenceSpinner.setEnabled( precedenceCheckbox.getSelection() ); } } ); precedenceSpinner = new Spinner( spinnerComposite, SWT.BORDER ); precedenceSpinner.setMinimum( 0 ); precedenceSpinner.setMaximum( 255 ); precedenceSpinner.setDigits( 0 ); precedenceSpinner.setIncrement( 1 ); precedenceSpinner.setPageIncrement( 10 ); precedenceSpinner.setSelection( 0 ); precedenceSpinner.setEnabled( false ); GridData precedenceGridData = new GridData(); precedenceGridData.grabExcessHorizontalSpace = true; precedenceGridData.verticalAlignment = GridData.CENTER; precedenceGridData.horizontalAlignment = GridData.BEGINNING; precedenceGridData.widthHint = 3 * 12; precedenceSpinner.setLayoutData( precedenceGridData ); // protected items protectedItemsComposite = new ACIItemProtectedItemsComposite( composite, SWT.NONE ); protectedItemsComposite.setContext( context ); // grants and denials grantsAndDenialsComposite = new ACIItemGrantsAndDenialsComposite( composite, SWT.NONE ); // set initial values if ( initialUserPermission != null ) { if ( ( initialUserPermission.getPrecedence() != null ) && ( initialUserPermission.getPrecedence() > -1 ) ) { precedenceCheckbox.setSelection( true ); precedenceSpinner.setEnabled( true ); precedenceSpinner.setSelection( initialUserPermission.getPrecedence() ); } protectedItemsComposite.setProtectedItems( initialUserPermission.getProtectedItems() ); grantsAndDenialsComposite.setGrantsAndDenials( initialUserPermission.getGrantsAndDenials() ); } applyDialogFont( composite ); return composite; } /** * Returns the user permission. Returns null if Cancel button was pressed. * * @return the composed user permission or null */ public UserPermission getUserPermission() { return returnUserPermission; } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/aciitemeditor/src/main/java/org/apache/directory/studio/aciitemeditor/dialogs/ItemPermissionDialog.java
plugins/aciitemeditor/src/main/java/org/apache/directory/studio/aciitemeditor/dialogs/ItemPermissionDialog.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.aciitemeditor.dialogs; import java.util.Collection; import org.apache.directory.api.ldap.aci.GrantAndDenial; import org.apache.directory.api.ldap.aci.ItemPermission; import org.apache.directory.api.ldap.aci.UserClass; import org.apache.directory.studio.aciitemeditor.ACIItemValueWithContext; import org.apache.directory.studio.aciitemeditor.Activator; import org.apache.directory.studio.aciitemeditor.widgets.ACIItemGrantsAndDenialsComposite; import org.apache.directory.studio.aciitemeditor.widgets.ACIItemUserClassesComposite; import org.eclipse.jface.dialogs.Dialog; import org.eclipse.jface.dialogs.IDialogConstants; import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.swt.SWT; 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.Composite; import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.widgets.Spinner; /** * A dialog to compose item permissions. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class ItemPermissionDialog extends Dialog { /** The context */ private ACIItemValueWithContext context; /** The initial value, passed by the constructor */ private ItemPermission initialItemPermission; /** The resulting value returned by getItemPermission() */ private ItemPermission returnItemPermission; /** The precedence checkbox to enable/disable spinner */ private Button precedenceCheckbox = null; /** The precedence spinner */ private Spinner precedenceSpinner = null; /** The widget with user classes table */ private ACIItemUserClassesComposite userClassesComposite; /** The widget with grants and denials table */ private ACIItemGrantsAndDenialsComposite grantsAndDenialsComposite; /** * Creates a new instance of ItemPermissionDialog. * * @param parentShell the shell * @param initialItemPermission the initial item permission * @param context the context */ public ItemPermissionDialog( Shell parentShell, ItemPermission initialItemPermission, ACIItemValueWithContext context ) { super( parentShell ); super.setShellStyle( super.getShellStyle() | SWT.RESIZE ); this.context = context; this.initialItemPermission = initialItemPermission; this.returnItemPermission = null; } /** * Sets the dialog image and text. * * {@inheritDoc} */ protected void configureShell( Shell shell ) { super.configureShell( shell ); shell.setText( Messages.getString( "ItemPermissionDialog.dialog.text" ) ); //$NON-NLS-1$ shell.setImage( Activator.getDefault().getImage( Messages.getString( "ItemPermissionDialog.dialog.icon" ) ) ); //$NON-NLS-1$ } /** * Reimplementation: Checks for valid syntax and sets the return value. */ protected void okPressed() { try { int precedence = precedenceCheckbox.getSelection() ? precedenceSpinner.getSelection() : -1; Collection<UserClass> userClasses = userClassesComposite.getUserClasses(); Collection<GrantAndDenial> grantsAndDenials = grantsAndDenialsComposite.getGrantsAndDenials(); returnItemPermission = new ItemPermission( precedence, grantsAndDenials, userClasses ); super.okPressed(); } catch ( Exception e ) { MessageDialog.openError( getShell(), Messages .getString( "ItemPermissionDialog.error.invalidItemPermission" ), e.getMessage() ); //$NON-NLS-1$ } } /** * Creates all the dialog content. * * @param parent the parent * * @return the control */ protected Control createDialogArea( Composite parent ) { Composite composite = ( Composite ) super.createDialogArea( parent ); GridData gd = new GridData( GridData.FILL_BOTH ); gd.widthHint = convertHorizontalDLUsToPixels( IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH ); gd.heightHint = convertVerticalDLUsToPixels( IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH ) * 4 / 3; composite.setLayoutData( gd ); // precedence Composite spinnerComposite = new Composite( composite, SWT.NONE ); spinnerComposite.setLayout( new GridLayout( 2, false ) ); spinnerComposite.setLayoutData( new GridData() ); precedenceCheckbox = new Button( spinnerComposite, SWT.CHECK ); precedenceCheckbox.setText( Messages.getString( "ItemPermissionDialog.precedence.label" ) ); //$NON-NLS-1$ precedenceCheckbox.addSelectionListener( new SelectionAdapter() { public void widgetSelected( SelectionEvent e ) { precedenceSpinner.setEnabled( precedenceCheckbox.getSelection() ); } } ); precedenceSpinner = new Spinner( spinnerComposite, SWT.BORDER ); precedenceSpinner.setMinimum( 0 ); precedenceSpinner.setMaximum( 255 ); precedenceSpinner.setDigits( 0 ); precedenceSpinner.setIncrement( 1 ); precedenceSpinner.setPageIncrement( 10 ); precedenceSpinner.setSelection( 0 ); precedenceSpinner.setEnabled( false ); GridData precedenceGridData = new GridData(); precedenceGridData.grabExcessHorizontalSpace = true; precedenceGridData.verticalAlignment = GridData.CENTER; precedenceGridData.horizontalAlignment = GridData.BEGINNING; precedenceGridData.widthHint = 3 * 12; precedenceSpinner.setLayoutData( precedenceGridData ); // user classes userClassesComposite = new ACIItemUserClassesComposite( composite, SWT.NONE ); userClassesComposite.setContext( context ); // grants and denial grantsAndDenialsComposite = new ACIItemGrantsAndDenialsComposite( composite, SWT.NONE ); // set initial values if ( initialItemPermission != null ) { if ( ( initialItemPermission.getPrecedence() != null ) && ( initialItemPermission.getPrecedence() > -1 ) ) { precedenceCheckbox.setSelection( true ); precedenceSpinner.setEnabled( true ); precedenceSpinner.setSelection( initialItemPermission.getPrecedence() ); } userClassesComposite.setUserClasses( initialItemPermission.getUserClasses() ); grantsAndDenialsComposite.setGrantsAndDenials( initialItemPermission.getGrantsAndDenials() ); } applyDialogFont( composite ); return composite; } /** * Returns the item permission. Returns null if Cancel button was pressed. * * @return the composed item permission or null */ public ItemPermission getItemPermission() { return returnItemPermission; } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/aciitemeditor/src/main/java/org/apache/directory/studio/aciitemeditor/dialogs/ACIItemDialog.java
plugins/aciitemeditor/src/main/java/org/apache/directory/studio/aciitemeditor/dialogs/ACIItemDialog.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.aciitemeditor.dialogs; import java.text.ParseException; import org.apache.directory.studio.aciitemeditor.ACIITemConstants; import org.apache.directory.studio.aciitemeditor.ACIItemValueWithContext; import org.apache.directory.studio.aciitemeditor.Activator; import org.apache.directory.studio.aciitemeditor.widgets.ACIItemTabFolderComposite; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Status; import org.eclipse.jface.dialogs.Dialog; import org.eclipse.jface.dialogs.ErrorDialog; import org.eclipse.jface.dialogs.IDialogConstants; import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.swt.SWT; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Shell; /** * The main dialog of the ACI item editor. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class ACIItemDialog extends Dialog { private static final int FORMAT_BUTTON = 987654321; private static final int CHECK_SYNTAX_BUTTON = 876543210; /** The context containing the initial value, passed by the constructor */ private ACIItemValueWithContext context; /** The resulting value returned by getACIItemValue() */ private String returnValue; /** The child composite with the tabs */ private ACIItemTabFolderComposite tabFolderComposite; /** * Creates a new instance of ACIItemDialog. * * @param parentShell the shell * @param context the context */ public ACIItemDialog( Shell parentShell, ACIItemValueWithContext context ) { super( parentShell ); super.setShellStyle( super.getShellStyle() | SWT.RESIZE ); assert context != null; assert context.getACIItemValue() != null; assert context.getConnection() != null; this.context = context; this.returnValue = null; } /** * Sets the dialog image and text. * * {@inheritDoc} */ protected void configureShell( Shell shell ) { super.configureShell( shell ); shell.setText( Messages.getString( "ACIItemDialog.dialog.text" ) ); //$NON-NLS-1$ shell.setImage( Activator.getDefault().getImage( Messages.getString( "ACIItemDialog.dialog.icon" ) ) ); //$NON-NLS-1$ } /** * @see org.eclipse.jface.dialogs.Dialog#createButtonsForButtonBar(org.eclipse.swt.widgets.Composite) */ protected void createButtonsForButtonBar( Composite parent ) { createButton( parent, FORMAT_BUTTON, Messages.getString( "ACIItemDialog.button.format" ), false ); //$NON-NLS-1$ createButton( parent, CHECK_SYNTAX_BUTTON, Messages.getString( "ACIItemDialog.button.checkSyntax" ), false ); //$NON-NLS-1$ createButton( parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, false ); createButton( parent, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL, false ); } /** * {@inheritDoc} * * This implementation checks if the Format button was pressed. */ protected void buttonPressed( int buttonId ) { if ( buttonId == FORMAT_BUTTON ) { tabFolderComposite.format(); } if ( buttonId == CHECK_SYNTAX_BUTTON ) { try { tabFolderComposite.getInput(); MessageDialog .openInformation( getShell(), Messages.getString( "ACIItemDialog.syntaxOk.title" ), Messages.getString( "ACIItemDialog.syntaxOk.text" ) ); //$NON-NLS-1$ //$NON-NLS-2$ } catch ( ParseException pe ) { IStatus status = new Status( IStatus.ERROR, ACIITemConstants.PLUGIN_ID, 1, Messages .getString( "ACIItemDialog.error.invalidSyntax" ), pe ); //$NON-NLS-1$ ErrorDialog.openError( getShell(), Messages.getString( "ACIItemDialog.error.title" ), null, status ); //$NON-NLS-1$ } } // call super implementation super.buttonPressed( buttonId ); } /** * Reimplementation: Checks for valid syntax first and sets the return value. */ protected void okPressed() { try { this.returnValue = tabFolderComposite.getInput(); super.okPressed(); } catch ( ParseException pe ) { IStatus status = new Status( IStatus.ERROR, ACIITemConstants.PLUGIN_ID, 1, Messages .getString( "ACIItemDialog.error.invalidSyntax" ), pe ); //$NON-NLS-1$ ErrorDialog.openError( getShell(), Messages.getString( "ACIItemDialog.error.title" ), null, status ); //$NON-NLS-1$ } } /** * Creates the tabFolderComposite. * * @param parent the parent * * @return the control */ protected Control createDialogArea( Composite parent ) { Composite composite = ( Composite ) super.createDialogArea( parent ); GridData gd = new GridData( GridData.FILL_BOTH ); gd.widthHint = convertHorizontalDLUsToPixels( IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH ) * 4 / 3; gd.heightHint = convertVerticalDLUsToPixels( IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH ) * 4 / 3; composite.setLayoutData( gd ); tabFolderComposite = new ACIItemTabFolderComposite( composite, SWT.NONE ); // set initial value if ( context != null ) { tabFolderComposite.setContext( context ); tabFolderComposite.setInput( context.getACIItemValue() ); } applyDialogFont( composite ); return composite; } /** * Returns the string representation of the ACI item. Returns * null if Cancel button was pressed. * * @return the string representation of the ACI item or null */ public String getACIItemValue() { return returnValue; } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/aciitemeditor/src/main/java/org/apache/directory/studio/aciitemeditor/dialogs/MultiValuedDialog.java
plugins/aciitemeditor/src/main/java/org/apache/directory/studio/aciitemeditor/dialogs/MultiValuedDialog.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.aciitemeditor.dialogs; import java.util.List; import org.apache.directory.studio.aciitemeditor.ACIItemValueWithContext; import org.apache.directory.studio.aciitemeditor.Activator; import org.apache.directory.studio.ldapbrowser.core.model.IAttribute; import org.apache.directory.studio.ldapbrowser.core.model.IValue; import org.apache.directory.studio.ldapbrowser.core.model.impl.Attribute; import org.apache.directory.studio.ldapbrowser.core.model.impl.Value; import org.apache.directory.studio.valueeditors.AbstractDialogStringValueEditor; import org.eclipse.jface.dialogs.Dialog; import org.eclipse.jface.dialogs.IDialogConstants; import org.eclipse.jface.viewers.ArrayContentProvider; import org.eclipse.jface.viewers.CellEditor; import org.eclipse.jface.viewers.DoubleClickEvent; import org.eclipse.jface.viewers.IDoubleClickListener; import org.eclipse.jface.viewers.ISelectionChangedListener; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jface.viewers.LabelProvider; import org.eclipse.jface.viewers.SelectionChangedEvent; 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.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.Shell; import org.eclipse.swt.widgets.Table; /** * Dialog to edit user classes or protected items with multiple values. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class MultiValuedDialog extends Dialog { /** The dialog title */ private String displayName; /** The value editor */ private AbstractDialogStringValueEditor valueEditor; /** The values, may be empty. */ private List<String> values; /** The context */ private ACIItemValueWithContext context; /** The inner composite for all the content */ private Composite composite = null; /** The table viewer containing all user classes */ private TableViewer tableViewer = null; /** The edit button */ private Button editButton = null; /** The delete button */ private Button deleteButton = null; /** * Creates a new instance of MultiValuedDialog. * * @param parentShell the shell * @param displayName the display name of the edited element * @param values a modifiable list of values * @param context the context * @param valueEditor the detail value editor */ public MultiValuedDialog( Shell parentShell, String displayName, List<String> values, ACIItemValueWithContext context, AbstractDialogStringValueEditor valueEditor ) { super( parentShell ); super.setShellStyle( super.getShellStyle() | SWT.RESIZE ); this.displayName = displayName; this.values = values; this.context = context; this.valueEditor = valueEditor; } /** * {@inheritDoc} * * Sets the dialog title. */ protected void configureShell( Shell shell ) { super.configureShell( shell ); shell.setText( Messages.getString( "MultiValuedDialog.dialog.titlePrefix" ) + displayName ); //$NON-NLS-1$ shell.setImage( Activator.getDefault().getImage( Messages.getString( "MultiValuedDialog.dialog.icon" ) ) ); //$NON-NLS-1$ } /** * {@inheritDoc} * * Creates only a OK button. */ protected void createButtonsForButtonBar( Composite parent ) { createButton( parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, false ); } /** * {@inheritDoc} */ protected Control createDialogArea( Composite parent ) { // create composite composite = ( Composite ) super.createDialogArea( parent ); GridData gd = new GridData( GridData.FILL_BOTH ); gd.widthHint = convertHorizontalDLUsToPixels( IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH ); gd.heightHint = convertHorizontalDLUsToPixels( IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH / 2 ); composite.setLayoutData( gd ); GridLayout layout = ( GridLayout ) composite.getLayout(); layout.makeColumnsEqualWidth = false; layout.numColumns = 2; createTable(); createButtonComposite(); applyDialogFont( composite ); return composite; } /** * This method initializes table and table viewer */ private void createTable() { GridData tableGridData = new GridData( GridData.FILL_BOTH ); tableGridData.grabExcessHorizontalSpace = true; tableGridData.verticalAlignment = GridData.FILL; tableGridData.horizontalAlignment = GridData.FILL; //tableGridData.heightHint = 100; Table table = new Table( composite, SWT.BORDER ); table.setHeaderVisible( false ); table.setLayoutData( tableGridData ); table.setLinesVisible( false ); tableViewer = new TableViewer( table ); tableViewer.setContentProvider( new ArrayContentProvider() ); tableViewer.setLabelProvider( new LabelProvider() ); tableViewer.setInput( values ); tableViewer.addSelectionChangedListener( new ISelectionChangedListener() { public void selectionChanged( SelectionChangedEvent event ) { valueSelected(); } } ); tableViewer.addDoubleClickListener( new IDoubleClickListener() { public void doubleClick( DoubleClickEvent event ) { editValue(); } } ); } /** * This method initializes buttons */ private void createButtonComposite() { GridData deleteButtonGridData = new GridData(); deleteButtonGridData.horizontalAlignment = GridData.FILL; deleteButtonGridData.grabExcessHorizontalSpace = false; deleteButtonGridData.verticalAlignment = GridData.BEGINNING; deleteButtonGridData.widthHint = Activator.getButtonWidth( composite ); GridData editButtonGridData = new GridData(); editButtonGridData.horizontalAlignment = GridData.FILL; editButtonGridData.grabExcessHorizontalSpace = false; editButtonGridData.verticalAlignment = GridData.BEGINNING; editButtonGridData.widthHint = Activator.getButtonWidth( composite ); GridData addButtonGridData = new GridData(); addButtonGridData.horizontalAlignment = GridData.FILL; addButtonGridData.grabExcessHorizontalSpace = false; addButtonGridData.verticalAlignment = GridData.BEGINNING; addButtonGridData.widthHint = Activator.getButtonWidth( composite ); GridLayout gridLayout = new GridLayout(); gridLayout.marginWidth = 0; gridLayout.marginHeight = 0; GridData gridData = new GridData(); gridData.horizontalAlignment = GridData.CENTER; gridData.grabExcessHorizontalSpace = false; gridData.grabExcessVerticalSpace = false; gridData.verticalAlignment = GridData.FILL; Composite buttonComposite = new Composite( composite, SWT.NONE ); buttonComposite.setLayoutData( gridData ); buttonComposite.setLayout( gridLayout ); Button addButton = new Button( buttonComposite, SWT.NONE ); addButton.setText( Messages.getString( "MultiValuedDialog.button.add" ) ); //$NON-NLS-1$ addButton.setLayoutData( addButtonGridData ); addButton.addSelectionListener( new SelectionAdapter() { public void widgetSelected( SelectionEvent e ) { addValue(); } } ); editButton = new Button( buttonComposite, SWT.NONE ); editButton.setText( Messages.getString( "MultiValuedDialog.button.edit" ) ); //$NON-NLS-1$ editButton.setLayoutData( editButtonGridData ); editButton.addSelectionListener( new SelectionAdapter() { public void widgetSelected( SelectionEvent e ) { editValue(); } } ); editButton.setEnabled( false ); deleteButton = new Button( buttonComposite, SWT.NONE ); deleteButton.setText( Messages.getString( "MultiValuedDialog.button.delete" ) ); //$NON-NLS-1$ deleteButton.setLayoutData( deleteButtonGridData ); deleteButton.addSelectionListener( new SelectionAdapter() { public void widgetSelected( SelectionEvent e ) { deleteValue(); } } ); deleteButton.setEnabled( false ); } /** * Opens the editor and adds the new value to the list. */ private void addValue() { IAttribute attribute = new Attribute( context.getEntry(), "" ); //$NON-NLS-1$ IValue value = new Value( attribute, "" ); //$NON-NLS-1$ Object oldRawValue = valueEditor.getRawValue( value ); //$NON-NLS-1$ CellEditor cellEditor = valueEditor.getCellEditor(); cellEditor.setValue( oldRawValue ); cellEditor.activate(); Object newRawValue = cellEditor.getValue(); if ( newRawValue != null ) { String newValue = ( String ) valueEditor.getStringOrBinaryValue( newRawValue ); values.add( newValue ); tableViewer.refresh(); } } /** * Opens the editor with the currently selected * value and puts the modified value into the list. */ private void editValue() { String oldValue = getSelectedValue(); if ( oldValue != null ) { IAttribute attribute = new Attribute( context.getEntry(), "" ); //$NON-NLS-1$ IValue value = new Value( attribute, oldValue ); //$NON-NLS-1$ Object oldRawValue = valueEditor.getRawValue( value ); //$NON-NLS-1$ CellEditor cellEditor = valueEditor.getCellEditor(); cellEditor.setValue( oldRawValue ); cellEditor.activate(); Object newRawValue = cellEditor.getValue(); if ( newRawValue != null ) { String newValue = ( String ) valueEditor.getStringOrBinaryValue( newRawValue ); values.remove( oldValue ); values.add( newValue ); tableViewer.refresh(); } } } /** * Deletes the currently selected value from list. */ private void deleteValue() { String value = getSelectedValue(); if ( value != null ) { values.remove( value ); tableViewer.refresh(); } } /** * Called when value is selected in table viewer. * Updates the enabled/disabled state of the buttons. */ private void valueSelected() { String value = getSelectedValue(); if ( value == null ) { editButton.setEnabled( false ); deleteButton.setEnabled( false ); } else { editButton.setEnabled( true ); deleteButton.setEnabled( true ); } } /** * @return the value that is selected in the table viewer, or null. */ private String getSelectedValue() { String value = null; IStructuredSelection selection = ( IStructuredSelection ) tableViewer.getSelection(); if ( !selection.isEmpty() ) { Object element = selection.getFirstElement(); if ( element instanceof String ) { value = ( String ) element; } } return value; } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/aciitemeditor/src/main/java/org/apache/directory/studio/aciitemeditor/valueeditors/RestrictedByValueEditor.java
plugins/aciitemeditor/src/main/java/org/apache/directory/studio/aciitemeditor/valueeditors/RestrictedByValueEditor.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.aciitemeditor.valueeditors; import java.util.Arrays; import java.util.Collection; import java.util.regex.Matcher; import java.util.regex.Pattern; import org.apache.directory.studio.aciitemeditor.Activator; import org.apache.directory.studio.common.ui.widgets.BaseWidgetUtils; import org.apache.directory.studio.connection.ui.widgets.ExtendedContentAssistCommandAdapter; import org.apache.directory.studio.ldapbrowser.common.dialogs.TextDialog; import org.apache.directory.studio.ldapbrowser.common.widgets.ListContentProposalProvider; import org.apache.directory.studio.ldapbrowser.core.model.IBrowserConnection; import org.apache.directory.studio.ldapbrowser.core.model.IValue; import org.apache.directory.studio.ldapbrowser.core.model.schema.Schema; import org.apache.directory.studio.ldapbrowser.core.model.schema.SchemaUtils; import org.apache.directory.studio.valueeditors.AbstractDialogStringValueEditor; import org.eclipse.jface.dialogs.Dialog; import org.eclipse.jface.dialogs.IDialogConstants; import org.eclipse.jface.fieldassist.ComboContentAdapter; 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.Control; import org.eclipse.swt.widgets.Shell; /** * ACI item editor specific value editor to edit the RestrictedBy protected item. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class RestrictedByValueEditor extends AbstractDialogStringValueEditor { private static final String L_CURLY_TYPE = "{ type "; //$NON-NLS-1$ private static final String SEP_VALUESIN = ", valuesIn "; //$NON-NLS-1$ private static final String R_CURLY = " }"; //$NON-NLS-1$ private static final String EMPTY = ""; //$NON-NLS-1$ /** * {@inheritDoc} * * This implementation opens the RestrictedByDialog. */ public boolean openDialog( Shell shell ) { Object value = getValue(); if ( value instanceof RestrictedByValueEditorRawValueWrapper ) { RestrictedByValueEditorRawValueWrapper wrapper = ( RestrictedByValueEditorRawValueWrapper ) value; RestrictedByDialog dialog = new RestrictedByDialog( shell, wrapper.schema, wrapper.type, wrapper.valuesIn ); if ( dialog.open() == TextDialog.OK && !EMPTY.equals( dialog.getType() ) && !EMPTY.equals( dialog.getValuesIn() ) ) { setValue( L_CURLY_TYPE + dialog.getType() + SEP_VALUESIN + dialog.getValuesIn() + R_CURLY ); return true; } } return false; } /** * {@inheritDoc} * * Returns an AttributeTypeAndValueValueEditorRawValueWrapper. */ public Object getRawValue( IValue value ) { if ( value != null ) { return getRawValue( value.getAttribute().getEntry().getBrowserConnection(), value .getStringValue() ); } return null; } private Object getRawValue( IBrowserConnection connection, Object value ) { Schema schema = null; if ( connection != null ) { schema = connection.getSchema(); } if ( schema == null || !( value instanceof String ) ) { return null; } String stringValue = ( String ) value; String type = EMPTY; String valuesIn = EMPTY; try { // for example: { type sn, valuesIn cn } Pattern pattern = Pattern .compile( "\\s*\\{\\s*type\\s*([^,\\s]*)\\s*,\\s*valuesIn\\s*([^,\\s]*)\\s*\\}\\s*" ); //$NON-NLS-1$ Matcher matcher = pattern.matcher( stringValue ); type = matcher.matches() ? matcher.group( 1 ) : EMPTY; valuesIn = matcher.matches() ? matcher.group( 2 ) : EMPTY; } catch ( Throwable e ) { e.printStackTrace(); } RestrictedByValueEditorRawValueWrapper wrapper = new RestrictedByValueEditorRawValueWrapper( schema, type, valuesIn ); return wrapper; } /** * The RestrictedByValueEditorRawValueWrapper is used to pass contextual * information to the opened RestrictedByDialog. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ private class RestrictedByValueEditorRawValueWrapper { /** * The schema, used in RestrictedByDialog to build the list * with possible attribute types. */ private final Schema schema; /** The type, used as initial type. */ private final String type; /** The values in, used as initial values in. */ private final String valuesIn; /** * Creates a new instance of RestrictedByValueEditorRawValueWrapper. * * @param schema the schema * @param type the type * @param valuesIn the values in */ private RestrictedByValueEditorRawValueWrapper( Schema schema, String type, String valuesIn ) { this.schema = schema; this.type = type; this.valuesIn = valuesIn; } } /** * This class provides a dialog to enter the RestrictedBy values. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ private class RestrictedByDialog extends Dialog { /** The schema. */ private Schema schema; /** The initial type. */ private String initialType; /** The initial values in. */ private String initialValuesIn; /** The type combo. */ private Combo typeCombo; /** The values in combo. */ private Combo valuesInCombo; /** The return type. */ private String returnType; /** The return values in. */ private String returnValuesIn; /** * Creates a new instance of RestrictedByDialog. * * @param parentShell the parent shell * @param schema the schema * @param initialType the initial type * @param initialValuesIn the initial values in */ public RestrictedByDialog( Shell parentShell, Schema schema, String initialType, String initialValuesIn ) { super( parentShell ); super.setShellStyle( super.getShellStyle() | SWT.RESIZE ); this.initialType = initialType; this.initialValuesIn = initialValuesIn; this.schema = schema; this.returnType = null; this.returnValuesIn = null; } /** * {@inheritDoc} */ protected void configureShell( Shell shell ) { super.configureShell( shell ); shell.setText( Messages.getString( "RestrictedByValueEditor.title" ) ); //$NON-NLS-1$ shell.setImage( Activator.getDefault().getImage( Messages.getString( "RestrictedByValueEditor.icon" ) ) ); //$NON-NLS-1$ } /** * {@inheritDoc} */ protected void okPressed() { returnType = typeCombo.getText(); returnValuesIn = valuesInCombo.getText(); super.okPressed(); } /** * {@inheritDoc} */ protected Control createDialogArea( Composite parent ) { // create composite Composite composite = ( Composite ) super.createDialogArea( parent ); GridData gd = new GridData( GridData.FILL_BOTH ); gd.widthHint = convertHorizontalDLUsToPixels( IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH ); composite.setLayoutData( gd ); composite.setLayout( new GridLayout( 5, false ) ); BaseWidgetUtils.createLabel( composite, L_CURLY_TYPE, 1 ); // combo widget Collection<String> names = SchemaUtils.getNames( schema.getAttributeTypeDescriptions() ); String[] allAtNames = names.toArray( new String[names.size()] ); Arrays.sort( allAtNames ); // type combo with field decoration and content proposal typeCombo = BaseWidgetUtils.createCombo( composite, allAtNames, -1, 1 ); typeCombo.setText( initialType ); new ExtendedContentAssistCommandAdapter( typeCombo, new ComboContentAdapter(), new ListContentProposalProvider( typeCombo.getItems() ), null, null, true ); BaseWidgetUtils.createLabel( composite, SEP_VALUESIN, 1 ); // valuesIn combo with field decoration and content proposal valuesInCombo = BaseWidgetUtils.createCombo( composite, allAtNames, -1, 1 ); valuesInCombo.setText( initialValuesIn ); new ExtendedContentAssistCommandAdapter( valuesInCombo, new ComboContentAdapter(), new ListContentProposalProvider( valuesInCombo.getItems() ), null, null, true ); BaseWidgetUtils.createLabel( composite, R_CURLY, 1 ); applyDialogFont( composite ); return composite; } /** * Gets the type. * * @return the type, null if canceled */ public String getType() { return returnType; } /** * Gets the values in. * * @return the values in, null if canceled */ public String getValuesIn() { return returnValuesIn; } } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/aciitemeditor/src/main/java/org/apache/directory/studio/aciitemeditor/valueeditors/AttributeTypeValueEditor.java
plugins/aciitemeditor/src/main/java/org/apache/directory/studio/aciitemeditor/valueeditors/AttributeTypeValueEditor.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.aciitemeditor.valueeditors; import org.apache.directory.studio.ldapbrowser.common.dialogs.TextDialog; import org.apache.directory.studio.ldapbrowser.core.model.IBrowserConnection; import org.apache.directory.studio.ldapbrowser.core.model.IValue; import org.apache.directory.studio.ldapbrowser.core.model.schema.Schema; import org.apache.directory.studio.valueeditors.AbstractDialogStringValueEditor; import org.eclipse.swt.widgets.Shell; /** * Implementation of IValueEditor for attribute types. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class AttributeTypeValueEditor extends AbstractDialogStringValueEditor { private static final String EMPTY = ""; //$NON-NLS-1$ /** * {@inheritDoc} * * This implementation opens the AttributeTypeDialog. */ public boolean openDialog( Shell shell ) { Object value = getValue(); if ( value instanceof AttributeTypeValueEditorRawValueWrapper ) { AttributeTypeValueEditorRawValueWrapper wrapper = ( AttributeTypeValueEditorRawValueWrapper ) value; AttributeTypeDialog dialog = new AttributeTypeDialog( shell, wrapper.schema, wrapper.attributeType ); if ( ( dialog.open() == TextDialog.OK ) && !EMPTY.equals( dialog.getAttributeType() ) ) { setValue( dialog.getAttributeType() ); return true; } } return false; } /** * {@inheritDoc} * * Returns an AttributeTypeAndValueValueEditorRawValueWrapper. */ public Object getRawValue( IValue value ) { if ( value != null ) { return getRawValue( value.getAttribute().getEntry().getBrowserConnection(), value.getStringValue() ); } return null; } private Object getRawValue( IBrowserConnection connection, Object value ) { Schema schema = null; if ( connection != null ) { schema = connection.getSchema(); } if ( ( schema == null ) || !( value instanceof String ) ) { return null; } String atValue = ( String ) value; AttributeTypeValueEditorRawValueWrapper wrapper = new AttributeTypeValueEditorRawValueWrapper( schema, atValue ); return wrapper; } /** * The AttributeTypeValueEditorRawValueWrapper is used to pass contextual * information to the opened AttributeTypeDialog. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ private class AttributeTypeValueEditorRawValueWrapper { /** * The schema, used in AttributeTypeDialog to build the list * with possible attribute types. */ private Schema schema; /** The attribute type, used as initial value in AttributeTypeDialog. */ private String attributeType; /** * Creates a new instance of AttributeTypeValueEditorRawValueWrapper. * * @param schema the schema * @param attributeType the attribute type */ private AttributeTypeValueEditorRawValueWrapper( Schema schema, String attributeType ) { super(); this.schema = schema; this.attributeType = attributeType; } } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/aciitemeditor/src/main/java/org/apache/directory/studio/aciitemeditor/valueeditors/ExclusionDialog.java
plugins/aciitemeditor/src/main/java/org/apache/directory/studio/aciitemeditor/valueeditors/ExclusionDialog.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.aciitemeditor.valueeditors; import java.util.regex.Matcher; import java.util.regex.Pattern; import org.apache.directory.api.ldap.model.exception.LdapInvalidDnException; import org.apache.directory.api.ldap.model.name.Dn; import org.apache.directory.studio.aciitemeditor.Activator; import org.apache.directory.studio.common.ui.widgets.BaseWidgetUtils; import org.apache.directory.studio.common.ui.widgets.WidgetModifyEvent; import org.apache.directory.studio.common.ui.widgets.WidgetModifyListener; import org.apache.directory.studio.ldapbrowser.common.widgets.search.EntryWidget; import org.apache.directory.studio.ldapbrowser.core.model.IBrowserConnection; import org.eclipse.jface.dialogs.Dialog; import org.eclipse.jface.dialogs.IDialogConstants; 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.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.Control; import org.eclipse.swt.widgets.Shell; /** * This class provides a dialog to enter the Exclusion values. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ class ExclusionDialog extends Dialog { /** The connection. */ private IBrowserConnection connection; /** The base. */ private Dn base; /** The initial type. */ private String initialType; /** The initial Dn */ private String initalDN; /** The return type */ private String returnType; /** The return Dn */ private String returnDN; private static final String EMPTY = ""; //$NON-NLS-1$ private static final String CHOP_BEFORE = "chopBefore"; //$NON-NLS-1$ private static final String CHOP_AFTER = "chopAfter"; //$NON-NLS-1$ // UI Fields private Combo typeCombo; private EntryWidget entryWidget; /** * Creates a new instance of ExclusionDialog. * * @param parentShell the parent shell * @param connection the connection * @param base the base Dn * @param exclusion the exclusion string */ protected ExclusionDialog( Shell parentShell, IBrowserConnection connection, Dn base, String exclusion ) { super( parentShell ); this.connection = connection; this.base = base; try { // for example: chopAfter: "ou=A" Pattern pattern = Pattern.compile( "\\s*(chopBefore|chopAfter):\\s*\"(.*)\"\\s*" ); //$NON-NLS-1$ Matcher matcher = pattern.matcher( exclusion ); initialType = matcher.matches() ? matcher.group( 1 ) : EMPTY; initalDN = matcher.matches() ? matcher.group( 2 ) : EMPTY; } catch ( Exception e ) { initialType = EMPTY; initalDN = EMPTY; } } /** * {@inheritDoc} */ protected void configureShell( Shell shell ) { super.configureShell( shell ); shell.setText( Messages.getString( "ExclusionValueEditor.title" ) ); //$NON-NLS-1$ shell.setImage( Activator.getDefault().getImage( Messages.getString( "ExclusionValueEditor.icon" ) ) ); //$NON-NLS-1$ } /** * {@inheritDoc} */ protected void okPressed() { returnType = typeCombo.getText(); returnDN = entryWidget.getDn().toString(); // save dn history entryWidget.saveDialogSettings(); super.okPressed(); } /** * {@inheritDoc} */ protected Control createDialogArea( Composite parent ) { Composite composite = ( Composite ) super.createDialogArea( parent ); GridData gd = new GridData( GridData.FILL_BOTH ); gd.widthHint = convertHorizontalDLUsToPixels( IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH ); composite.setLayoutData( gd ); composite.setLayout( new GridLayout( 3, false ) ); BaseWidgetUtils.createLabel( composite, Messages.getString( "ExclusionValueEditor.label.type" ), 1 ); //$NON-NLS-1$ typeCombo = new Combo( composite, SWT.READ_ONLY ); String[] types = new String[2]; types[0] = CHOP_BEFORE; types[1] = CHOP_AFTER; ComboViewer typeComboViewer = new ComboViewer( typeCombo ); typeComboViewer.setContentProvider( new ArrayContentProvider() ); typeComboViewer.setLabelProvider( new LabelProvider() ); typeComboViewer.setInput( types ); typeComboViewer.setSelection( new StructuredSelection( CHOP_BEFORE ), true ); typeComboViewer.setSelection( new StructuredSelection( initialType ), true ); GridData gridData = new GridData(); gridData.horizontalSpan = 2; gridData.grabExcessHorizontalSpace = true; gridData.verticalAlignment = GridData.CENTER; gridData.horizontalAlignment = GridData.BEGINNING; typeCombo.setLayoutData( gridData ); BaseWidgetUtils.createLabel( composite, Messages.getString( "ExclusionValueEditor.label.rdn" ), 1 ); //$NON-NLS-1$ entryWidget = new EntryWidget( connection, null, base, true ); entryWidget.createWidget( composite ); try { Dn dn = new Dn( initalDN ); entryWidget.setInput( connection, dn, base, true ); } catch ( LdapInvalidDnException e ) { } entryWidget.addWidgetModifyListener( new WidgetModifyListener() { public void widgetModified( WidgetModifyEvent event ) { validate(); } } ); validate(); return composite; } /** * Validates if the dn is valid. */ private void validate() { boolean valid = entryWidget.getDn() != null && entryWidget.getDn().size() > 0; if ( getButton( IDialogConstants.OK_ID ) != null ) { getButton( IDialogConstants.OK_ID ).setEnabled( valid ); } } /** * Get the type. * * @return * the type, null if canceled */ public String getType() { return returnType; } /** * Gets the Dn. * * @return * the Dn, null if canceled */ public String getDN() { return returnDN; } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/aciitemeditor/src/main/java/org/apache/directory/studio/aciitemeditor/valueeditors/package-info.java
plugins/aciitemeditor/src/main/java/org/apache/directory/studio/aciitemeditor/valueeditors/package-info.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. * */ /** * Contains all ACI item editor specific inner value editors. */ package org.apache.directory.studio.aciitemeditor.valueeditors;
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/aciitemeditor/src/main/java/org/apache/directory/studio/aciitemeditor/valueeditors/AttributeTypeDialog.java
plugins/aciitemeditor/src/main/java/org/apache/directory/studio/aciitemeditor/valueeditors/AttributeTypeDialog.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.aciitemeditor.valueeditors; import java.util.Arrays; import java.util.Collection; import org.apache.directory.studio.aciitemeditor.Activator; import org.apache.directory.studio.common.ui.widgets.BaseWidgetUtils; import org.apache.directory.studio.connection.ui.widgets.ExtendedContentAssistCommandAdapter; import org.apache.directory.studio.ldapbrowser.common.widgets.ListContentProposalProvider; import org.apache.directory.studio.ldapbrowser.core.model.schema.Schema; import org.apache.directory.studio.ldapbrowser.core.model.schema.SchemaUtils; import org.eclipse.jface.dialogs.Dialog; import org.eclipse.jface.dialogs.IDialogConstants; import org.eclipse.jface.fieldassist.ComboContentAdapter; import org.eclipse.swt.SWT; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.widgets.Combo; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Shell; /** * This class provides a dialog to enter or select an attribute type. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class AttributeTypeDialog extends Dialog { /** The schema. */ private Schema schema; /** The initial value. */ private String initialValue; /** The attribute type combo. */ private Combo attributeTypeCombo; /** The return value. */ private String returnValue; /** * Creates a new instance of AttributeTypeDialog. * * @param parentShell the parent shell * @param schema the schema * @param initialValue the initial value */ public AttributeTypeDialog( Shell parentShell, Schema schema, String initialValue ) { super( parentShell ); super.setShellStyle( super.getShellStyle() | SWT.RESIZE ); this.initialValue = initialValue; this.schema = schema; this.returnValue = null; } /** * {@inheritDoc} */ protected void configureShell( Shell shell ) { super.configureShell( shell ); shell.setText( Messages.getString( "AttributeTypeDialog.title" ) ); //$NON-NLS-1$ shell.setImage( Activator.getDefault().getImage( Messages.getString( "AttributeTypeDialog.icon" ) ) ); //$NON-NLS-1$ } /** * {@inheritDoc} */ protected void createButtonsForButtonBar( Composite parent ) { super.createButtonsForButtonBar( parent ); } /** * {@inheritDoc} */ protected void okPressed() { returnValue = attributeTypeCombo.getText(); super.okPressed(); } /** * {@inheritDoc} */ protected Control createDialogArea( Composite parent ) { // create composite Composite composite = ( Composite ) super.createDialogArea( parent ); GridData gd = new GridData( GridData.FILL_BOTH ); gd.widthHint = convertHorizontalDLUsToPixels( IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH ); composite.setLayoutData( gd ); // combo widget Collection<String> names = SchemaUtils.getNames( schema.getAttributeTypeDescriptions() ); String[] allAtNames = names.toArray( new String[names.size()] ); Arrays.sort( allAtNames ); // attribute combo with field decoration and content proposal attributeTypeCombo = BaseWidgetUtils.createCombo( composite, allAtNames, -1, 1 ); attributeTypeCombo.setText( initialValue ); new ExtendedContentAssistCommandAdapter( attributeTypeCombo, new ComboContentAdapter(), new ListContentProposalProvider( attributeTypeCombo.getItems() ), null, null, true ); applyDialogFont( composite ); return composite; } /** * Gets the attribute type. * * @return the attribute type, null if canceled */ public String getAttributeType() { return returnValue; } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/aciitemeditor/src/main/java/org/apache/directory/studio/aciitemeditor/valueeditors/AttributeTypeAndValueDialog.java
plugins/aciitemeditor/src/main/java/org/apache/directory/studio/aciitemeditor/valueeditors/AttributeTypeAndValueDialog.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.aciitemeditor.valueeditors; import java.util.Arrays; import java.util.Collection; import org.apache.directory.studio.aciitemeditor.Activator; import org.apache.directory.studio.common.ui.widgets.BaseWidgetUtils; import org.apache.directory.studio.connection.ui.widgets.ExtendedContentAssistCommandAdapter; import org.apache.directory.studio.ldapbrowser.common.widgets.ListContentProposalProvider; import org.apache.directory.studio.ldapbrowser.core.model.schema.Schema; import org.apache.directory.studio.ldapbrowser.core.model.schema.SchemaUtils; import org.eclipse.jface.dialogs.Dialog; import org.eclipse.jface.dialogs.IDialogConstants; import org.eclipse.jface.fieldassist.ComboContentAdapter; 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.Control; import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.widgets.Text; /** * This class provides a dialog to enter an attribute type and value. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class AttributeTypeAndValueDialog extends Dialog { /** The schema. */ private Schema schema; /** The initial attribute type. */ private String initialAttributeType; /** The initial value. */ private String initialValue; /** The attribute type combo. */ private Combo attributeTypeCombo; /** The value text. */ private Text valueText; /** The return attribute type. */ private String returnAttributeType; /** The return value. */ private String returnValue; /** * Creates a new instance of AttributeTypeDialog. * * @param parentShell the parent shell * @param schema the schema * @param initialAttributeType the initial attribute type * @param initialValue the initial value */ public AttributeTypeAndValueDialog( Shell parentShell, Schema schema, String initialAttributeType, String initialValue ) { super( parentShell ); super.setShellStyle( super.getShellStyle() | SWT.RESIZE ); this.initialAttributeType = initialAttributeType; this.initialValue = initialValue; this.schema = schema; this.returnValue = null; } /** * {@inheritDoc} */ protected void configureShell( Shell shell ) { super.configureShell( shell ); shell.setText( Messages.getString( "AttributeTypeAndValueDialog.title" ) ); //$NON-NLS-1$ shell.setImage( Activator.getDefault().getImage( Messages.getString( "AttributeTypeAndValueDialog.icon" ) ) ); //$NON-NLS-1$ } /** * {@inheritDoc} */ protected void okPressed() { returnAttributeType = attributeTypeCombo.getText(); returnValue = valueText.getText(); super.okPressed(); } /** * {@inheritDoc} */ protected Control createDialogArea( Composite parent ) { // create composite Composite composite = ( Composite ) super.createDialogArea( parent ); GridData gd = new GridData( GridData.FILL_BOTH ); gd.widthHint = convertHorizontalDLUsToPixels( IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH ); composite.setLayoutData( gd ); composite.setLayout( new GridLayout( 3, false ) ); // combo widget Collection<String> names = SchemaUtils.getNames( schema.getAttributeTypeDescriptions() ); String[] allAtNames = names.toArray( new String[names.size()] ); Arrays.sort( allAtNames ); // attribute combo with field decoration and content proposal attributeTypeCombo = BaseWidgetUtils.createCombo( composite, allAtNames, -1, 1 ); attributeTypeCombo.setText( initialAttributeType ); new ExtendedContentAssistCommandAdapter( attributeTypeCombo, new ComboContentAdapter(), new ListContentProposalProvider( attributeTypeCombo.getItems() ), null, null, true ); BaseWidgetUtils.createLabel( composite, " = ", 1 ); //$NON-NLS-1$ valueText = BaseWidgetUtils.createText( composite, initialValue, 1 ); applyDialogFont( composite ); return composite; } /** * Gets the attribute type. * * @return the attribute type, null if canceled */ public String getAttributeType() { return returnAttributeType; } /** * Gets the value. * * @return the value, null if canceled */ public String getValue() { return returnValue; } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/aciitemeditor/src/main/java/org/apache/directory/studio/aciitemeditor/valueeditors/FilterValueEditor.java
plugins/aciitemeditor/src/main/java/org/apache/directory/studio/aciitemeditor/valueeditors/FilterValueEditor.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.aciitemeditor.valueeditors; import org.apache.directory.studio.ldapbrowser.common.dialogs.FilterWidgetDialog; import org.apache.directory.studio.ldapbrowser.common.dialogs.TextDialog; import org.apache.directory.studio.ldapbrowser.core.model.IBrowserConnection; import org.apache.directory.studio.ldapbrowser.core.model.IValue; import org.apache.directory.studio.valueeditors.AbstractDialogStringValueEditor; import org.eclipse.swt.widgets.Shell; /** * Implementation of IValueEditor for LDAP filters. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class FilterValueEditor extends AbstractDialogStringValueEditor { private static final String EMPTY = ""; //$NON-NLS-1$ /** * {@inheritDoc} * * This implementation opens the FilterWidgetDialog. */ public boolean openDialog( Shell shell ) { Object value = getValue(); if ( value instanceof FilterValueEditorRawValueWrapper ) { FilterValueEditorRawValueWrapper wrapper = ( FilterValueEditorRawValueWrapper ) value; FilterWidgetDialog dialog = new FilterWidgetDialog( shell, Messages .getString( "FilterValueEditor.dialog.title" ), wrapper.filter, //$NON-NLS-1$ wrapper.connection ); if ( dialog.open() == TextDialog.OK && !EMPTY.equals( dialog.getFilter() ) ) { setValue( dialog.getFilter() ); return true; } } return false; } /** * {@inheritDoc} * * Returns an AttributeTypeAndValueValueEditorRawValueWrapper. */ public Object getRawValue( IValue value ) { if ( value != null ) { return getRawValue( value.getAttribute().getEntry().getBrowserConnection(), value.getStringValue() ); } else { return null; } } private Object getRawValue( IBrowserConnection connection, Object value ) { if ( connection == null || !( value instanceof String ) ) { return null; } String filterValue = ( String ) value; FilterValueEditorRawValueWrapper wrapper = new FilterValueEditorRawValueWrapper( connection, filterValue ); return wrapper; } /** * The FilterValueEditorRawValueWrapper is used to pass contextual * information to the opened FilterDialog. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ private class FilterValueEditorRawValueWrapper { /** * The connection, used in FilterDialog to build the list * with possible attribute types. */ private IBrowserConnection connection; /** The filter, used as initial value in FilterDialog. */ private String filter; /** * Creates a new instance of FilterValueEditorRawValueWrapper. * * @param schema the schema * @param attributeType the attribute type */ private FilterValueEditorRawValueWrapper( IBrowserConnection connection, String filter ) { this.connection = connection; this.filter = filter; } } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/aciitemeditor/src/main/java/org/apache/directory/studio/aciitemeditor/valueeditors/Messages.java
plugins/aciitemeditor/src/main/java/org/apache/directory/studio/aciitemeditor/valueeditors/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.aciitemeditor.valueeditors; 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 final 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/aciitemeditor/src/main/java/org/apache/directory/studio/aciitemeditor/valueeditors/SubtreeSpecificationDialog.java
plugins/aciitemeditor/src/main/java/org/apache/directory/studio/aciitemeditor/valueeditors/SubtreeSpecificationDialog.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.aciitemeditor.valueeditors; import java.text.ParseException; import java.util.ArrayList; import java.util.List; import java.util.Set; import org.apache.directory.api.ldap.model.exception.LdapInvalidDnException; import org.apache.directory.api.ldap.model.name.Dn; import org.apache.directory.api.ldap.model.subtree.BaseSubtreeSpecification; import org.apache.directory.api.ldap.model.subtree.SubtreeSpecification; import org.apache.directory.api.ldap.model.subtree.SubtreeSpecificationParser; import org.apache.directory.studio.aciitemeditor.Activator; import org.apache.directory.studio.common.ui.widgets.BaseWidgetUtils; import org.apache.directory.studio.common.ui.widgets.WidgetModifyEvent; import org.apache.directory.studio.common.ui.widgets.WidgetModifyListener; import org.apache.directory.studio.ldapbrowser.common.dialogs.TextDialog; import org.apache.directory.studio.ldapbrowser.common.widgets.search.EntryWidget; import org.apache.directory.studio.ldapbrowser.common.widgets.search.FilterWidget; import org.apache.directory.studio.ldapbrowser.core.model.IBrowserConnection; 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.IStructuredSelection; import org.eclipse.jface.viewers.LabelProvider; import org.eclipse.jface.viewers.SelectionChangedEvent; import org.eclipse.jface.viewers.TableViewer; import org.eclipse.swt.SWT; import org.eclipse.swt.events.ModifyEvent; import org.eclipse.swt.events.ModifyListener; import org.eclipse.swt.events.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.Composite; import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.widgets.Spinner; import org.eclipse.swt.widgets.Table; import org.eclipse.swt.widgets.Text; /** * This class provides a dialog to enter the Subtree Specification value. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ class SubtreeSpecificationDialog extends Dialog { /** The parser. */ private final SubtreeSpecificationParser parser = new SubtreeSpecificationParser( null ); /** The connection */ private IBrowserConnection connection; /** The subentry's Dn */ private Dn subentryDn; /** Flag indicating if the refinement or filter widget should be visible */ private boolean refinementOrFilterVisible; /** Flag indicating if a local name should be used for the base */ private boolean useLocalName; /** The initial SubtreeSpecification */ private SubtreeSpecification subtreeSpecification; /** The Exclusions List */ private List<String> exclusions; /** The returned SubtreeSpecification */ private String returnValue; // UI Fields private EntryWidget entryWidget; private Spinner minimumSpinner; private Spinner maximumSpinner; private TableViewer exclusionsTableViewer; private Button exclusionsTableEditButton; private Button exclusionsTableDeleteButton; private Button refinementButton; private Text refinementText; private Button filterButton; private FilterWidget filterWidget; /** * Creates a new instance of SubtreeSpecificationDialog. * * @param shell * the shell to use * @param connection * the connection to use * @param subentryDn * the subentry's Dn * @param initialSubtreeSpecification * the initial SubtreeSpecification * @param refinementOrFilterVisible * true if the refinement of filter widget should be visible * @param useLocalName * true to use local name for the base */ SubtreeSpecificationDialog( Shell shell, IBrowserConnection connection, Dn subentryDn, String initialSubtreeSpecification, boolean refinementOrFilterVisible, boolean useLocalName ) { super( shell ); this.connection = connection; this.subentryDn = subentryDn; this.refinementOrFilterVisible = refinementOrFilterVisible; this.useLocalName = useLocalName; // parse try { subtreeSpecification = parser.parse( initialSubtreeSpecification ); if ( subtreeSpecification == null ) { subtreeSpecification = new BaseSubtreeSpecification(); } } catch ( ParseException pe ) { // TODO pe.printStackTrace(); subtreeSpecification = new BaseSubtreeSpecification(); } exclusions = new ArrayList<String>(); Set<Dn> chopBeforeExclusions = subtreeSpecification.getChopBeforeExclusions(); for ( Dn dn : chopBeforeExclusions ) { exclusions.add( "chopBefore: \"" + dn.getNormName() + "\"" ); //$NON-NLS-1$ //$NON-NLS-2$ } Set<Dn> chopAfterExclusions = subtreeSpecification.getChopAfterExclusions(); for ( Dn dn : chopAfterExclusions ) { exclusions.add( "chopAfter: \"" + dn.getNormName() + "\"" ); //$NON-NLS-1$ //$NON-NLS-2$ } returnValue = null; } /** * {@inheritDoc} */ protected void configureShell( Shell newShell ) { super.configureShell( newShell ); newShell.setText( Messages.getString( "SubtreeValueEditor.title" ) ); //$NON-NLS-1$ newShell.setImage( Activator.getDefault().getImage( Messages.getString( "SubtreeValueEditor.icon" ) ) ); //$NON-NLS-1$ } /** * {@inheritDoc} */ protected void okPressed() { // set return value //returnValue = buildSubreeSpecification(); StringBuilder sb = new StringBuilder(); subtreeSpecification.toString( sb ); returnValue = sb.toString(); // save filter and dn history if ( refinementOrFilterVisible ) { filterWidget.saveDialogSettings(); } entryWidget.saveDialogSettings(); super.okPressed(); } /** * {@inheritDoc} */ protected Control createDialogArea( Composite parent ) { Composite outer = ( Composite ) super.createDialogArea( parent ); GridData gd = new GridData( GridData.FILL_BOTH ); gd.widthHint = convertHorizontalDLUsToPixels( IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH ); outer.setLayoutData( gd ); Composite composite = BaseWidgetUtils.createColumnContainer( outer, 3, 1 ); BaseWidgetUtils.createLabel( composite, Messages.getString( "SubtreeValueEditor.label.base" ), 1 ); //$NON-NLS-1$ Dn base = subtreeSpecification.getBase(); Dn suffix = null; if ( subentryDn != null ) { suffix = subentryDn.getParent(); } entryWidget = new EntryWidget( connection, base, suffix, useLocalName ); entryWidget.createWidget( composite ); entryWidget.addWidgetModifyListener( new WidgetModifyListener() { public void widgetModified( WidgetModifyEvent event ) { validate(); } } ); GridData spinnersGridData = new GridData(); spinnersGridData.grabExcessHorizontalSpace = true; spinnersGridData.verticalAlignment = GridData.CENTER; spinnersGridData.horizontalSpan = 2; spinnersGridData.horizontalAlignment = GridData.BEGINNING; spinnersGridData.widthHint = 3 * 12; BaseWidgetUtils.createLabel( composite, Messages.getString( "SubtreeValueEditor.label.minimum" ), 1 ); //$NON-NLS-1$ minimumSpinner = new Spinner( composite, SWT.BORDER ); minimumSpinner.setMinimum( 0 ); minimumSpinner.setMaximum( Integer.MAX_VALUE ); minimumSpinner.setDigits( 0 ); minimumSpinner.setIncrement( 1 ); minimumSpinner.setPageIncrement( 100 ); minimumSpinner.setSelection( subtreeSpecification.getMinBaseDistance() ); minimumSpinner.setLayoutData( spinnersGridData ); minimumSpinner.addModifyListener( new ModifyListener() { public void modifyText( ModifyEvent event ) { validate(); } } ); BaseWidgetUtils.createLabel( composite, Messages.getString( "SubtreeValueEditor.label.maximum" ), 1 ); //$NON-NLS-1$ maximumSpinner = new Spinner( composite, SWT.BORDER ); maximumSpinner.setMinimum( 0 ); maximumSpinner.setMaximum( Integer.MAX_VALUE ); maximumSpinner.setDigits( 0 ); maximumSpinner.setIncrement( 1 ); maximumSpinner.setPageIncrement( 100 ); maximumSpinner.setSelection( subtreeSpecification.getMaxBaseDistance() ); maximumSpinner.setLayoutData( spinnersGridData ); maximumSpinner.addModifyListener( new ModifyListener() { public void modifyText( ModifyEvent event ) { validate(); } } ); createExclusionsTable( composite ); if ( refinementOrFilterVisible ) { BaseWidgetUtils.createSpacer( composite, 3 ); createRefinementOrFilterWidgets( composite ); } applyDialogFont( outer ); validate(); return outer; } /** * Creates the Exclusions Table. * * @param composite * the composite */ private void createExclusionsTable( Composite composite ) { GridData tableGridData = new GridData(); tableGridData.grabExcessHorizontalSpace = true; tableGridData.verticalAlignment = GridData.FILL; tableGridData.horizontalAlignment = GridData.FILL; tableGridData.heightHint = 100; BaseWidgetUtils.createLabel( composite, Messages.getString( "SubtreeValueEditor.label.exclusions" ), 1 ); //$NON-NLS-1$ Table exclusionsTable = new Table( composite, SWT.BORDER ); exclusionsTable.setHeaderVisible( false ); exclusionsTable.setLayoutData( tableGridData ); exclusionsTable.setLinesVisible( false ); exclusionsTableViewer = new TableViewer( exclusionsTable ); exclusionsTableViewer.setContentProvider( new ArrayContentProvider() ); exclusionsTableViewer.setLabelProvider( new LabelProvider() ); exclusionsTableViewer.setInput( exclusions ); exclusionsTableViewer.addSelectionChangedListener( new ISelectionChangedListener() { public void selectionChanged( SelectionChangedEvent event ) { valueSelectedExclusionsTable(); } } ); exclusionsTableViewer.addDoubleClickListener( new IDoubleClickListener() { public void doubleClick( DoubleClickEvent event ) { editValueExclusionsTable(); } } ); GridLayout gridLayout = new GridLayout(); gridLayout.marginWidth = 0; gridLayout.marginHeight = 0; GridData gridData = new GridData(); gridData.horizontalAlignment = GridData.CENTER; gridData.grabExcessHorizontalSpace = false; gridData.grabExcessVerticalSpace = false; gridData.verticalAlignment = GridData.FILL; Composite buttonComposite = new Composite( composite, SWT.NONE ); buttonComposite.setLayoutData( gridData ); buttonComposite.setLayout( gridLayout ); GridData buttonGridData = new GridData(); buttonGridData.horizontalAlignment = GridData.FILL; buttonGridData.grabExcessHorizontalSpace = false; buttonGridData.verticalAlignment = GridData.BEGINNING; buttonGridData.widthHint = Activator.getButtonWidth( buttonComposite ); Button exclusionsTableAddButton = new Button( buttonComposite, SWT.PUSH ); exclusionsTableAddButton.setText( Messages.getString( "SubtreeValueEditor.button.add" ) ); //$NON-NLS-1$ exclusionsTableAddButton.setLayoutData( buttonGridData ); exclusionsTableAddButton.addSelectionListener( new SelectionAdapter() { public void widgetSelected( SelectionEvent e ) { addValueExclusionsTable(); } } ); exclusionsTableEditButton = new Button( buttonComposite, SWT.PUSH ); exclusionsTableEditButton.setText( Messages.getString( "SubtreeValueEditor.button.edit" ) ); //$NON-NLS-1$ exclusionsTableEditButton.setLayoutData( buttonGridData ); exclusionsTableEditButton.addSelectionListener( new SelectionAdapter() { public void widgetSelected( SelectionEvent e ) { editValueExclusionsTable(); } } ); exclusionsTableEditButton.setEnabled( false ); exclusionsTableDeleteButton = new Button( buttonComposite, SWT.PUSH ); exclusionsTableDeleteButton.setText( Messages.getString( "SubtreeValueEditor.button.delete" ) ); //$NON-NLS-1$ exclusionsTableDeleteButton.setLayoutData( buttonGridData ); exclusionsTableDeleteButton.addSelectionListener( new SelectionAdapter() { public void widgetSelected( SelectionEvent e ) { deleteValueExclusionsTable(); } } ); exclusionsTableDeleteButton.setEnabled( false ); } /** * Creates the refinement or filter widgets * * @param composite * the composite */ private void createRefinementOrFilterWidgets( Composite parent ) { // Messages.getString( "SubtreeValueEditor.label.exclusions" ) BaseWidgetUtils.createLabel( parent, Messages .getString( "SubtreeValueEditor.SubtreeValueEditor.label.refinementOrFilter" ), 1 ); //$NON-NLS-1$ Composite composite = BaseWidgetUtils.createColumnContainer( parent, 2, 2 ); // refinement redio button refinementButton = BaseWidgetUtils.createRadiobutton( composite, Messages .getString( "SubtreeValueEditor.SubtreeValueEditor.label.refinement" ), 2 ); //$NON-NLS-1$ // refinement text refinementText = new Text( composite, SWT.MULTI | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL ); GridData gd = new GridData( GridData.FILL_BOTH ); gd.horizontalSpan = 2; gd.widthHint = convertHorizontalDLUsToPixels( IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH ); gd.heightHint = convertHorizontalDLUsToPixels( IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH / 6 ); refinementText.setLayoutData( gd ); try { StringBuilder refinementBuffer = new StringBuilder(); if ( subtreeSpecification.getRefinement() != null ) { subtreeSpecification.getRefinement().printRefinementToBuffer( refinementBuffer ); } refinementText.setText( refinementBuffer.toString().trim() ); refinementText.setEnabled( true ); refinementButton.setSelection( true ); } catch ( UnsupportedOperationException e ) { // thrown if the ExprNode doesn't represent a valid refinement refinementText.setText( "" ); //$NON-NLS-1$ refinementText.setEnabled( false ); refinementButton.setSelection( false ); } // filter radio button filterButton = BaseWidgetUtils.createRadiobutton( composite, Messages .getString( "SubtreeValueEditor.SubtreeValueEditor.label.filter" ), 2 ); //$NON-NLS-1$ // filter widget String filter = ""; //$NON-NLS-1$ if ( subtreeSpecification.getRefinement() != null ) { filter = subtreeSpecification.getRefinement().toString(); } filterWidget = new FilterWidget( filter ); filterWidget.createWidget( composite ); filterWidget.setBrowserConnection( connection ); filterButton.setSelection( !refinementButton.getSelection() ); filterWidget.setEnabled( !refinementButton.getSelection() ); // add listeners refinementButton.addSelectionListener( new SelectionAdapter() { public void widgetSelected( SelectionEvent arg0 ) { refinementText.setEnabled( true ); //filterButton.setSelection( false ); filterWidget.setEnabled( false ); validate(); } } ); refinementText.addModifyListener( new ModifyListener() { public void modifyText( ModifyEvent event ) { validate(); } } ); filterButton.addSelectionListener( new SelectionAdapter() { public void widgetSelected( SelectionEvent arg0 ) { //refinementButton.setSelection( false ); refinementText.setEnabled( false ); filterWidget.setEnabled( true ); validate(); } } ); filterWidget.addWidgetModifyListener( new WidgetModifyListener() { public void widgetModified( WidgetModifyEvent event ) { validate(); } } ); } /** * Validates if the composed subtree specification is valid. */ private void validate() { boolean valid = true; Dn base = entryWidget.getDn(); valid &= base != null; String ss = buildSubreeSpecification(); try { subtreeSpecification = parser.parse( ss ); valid &= true; } catch ( ParseException pe ) { subtreeSpecification = null; valid &= false; } if ( refinementOrFilterVisible && filterButton.getSelection() ) { valid &= filterWidget.getFilter() != null; } if ( getButton( IDialogConstants.OK_ID ) != null ) { getButton( IDialogConstants.OK_ID ).setEnabled( valid ); } } private String buildSubreeSpecification() { // build subtree specification tree StringBuilder sb = new StringBuilder(); sb.append( "{" ); //$NON-NLS-1$ // Adding base Dn base = entryWidget.getDn(); if ( ( base != null ) && !SubtreeValueEditor.EMPTY.equals( base.toString() ) ) { sb.append( " base \"" ); sb.append( base.toString() ); sb.append( "\"," ); //$NON-NLS-1$ //$NON-NLS-2$ } // Adding Minimum int minimum = minimumSpinner.getSelection(); if ( minimum != 0 ) { sb.append( " minimum " ).append( minimum ).append( ',' ); //$NON-NLS-1$ //$NON-NLS-2$ } // Adding Maximum int maximum = maximumSpinner.getSelection(); if ( maximum != 0 ) { sb.append( " maximum " ).append( maximum ).append( ',' ); //$NON-NLS-1$ //$NON-NLS-2$ } // Adding Exclusions if ( !exclusions.isEmpty() ) { sb.append( " specificExclusions {" ); //$NON-NLS-1$ boolean isFirst = true; for ( String exclusion : exclusions ) { if ( isFirst ) { isFirst = false; } else { sb.append( ',' ); } sb.append( ' ' ).append( exclusion ); //$NON-NLS-1$ } sb.append( " }," ); //$NON-NLS-1$ } // Add Refinement or Filter String refinementOrFilter = ""; //$NON-NLS-1$ if ( refinementOrFilterVisible ) { if ( refinementButton.getSelection() ) { refinementOrFilter = refinementText.getText(); } else { refinementOrFilter = filterWidget.getFilter(); } } else { refinementOrFilter = ""; //$NON-NLS-1$ } if ( refinementOrFilter != null && !SubtreeValueEditor.EMPTY.equals( refinementOrFilter ) ) { sb.append( " specificationFilter " + refinementOrFilter + "," ); //$NON-NLS-1$ //$NON-NLS-2$ } // Removing the last ',' if ( sb.charAt( sb.length() - 1 ) == ',' ) { sb.deleteCharAt( sb.length() - 1 ); } sb.append( " }" ); //$NON-NLS-1$ return sb.toString(); } /** * Called when value is selected in Exclusions table viewer. * Updates the enabled/disabled state of the buttons. */ private void valueSelectedExclusionsTable() { String value = getSelectedValueExclusionsTable(); if ( value == null ) { exclusionsTableEditButton.setEnabled( false ); exclusionsTableDeleteButton.setEnabled( false ); } else { exclusionsTableEditButton.setEnabled( true ); exclusionsTableDeleteButton.setEnabled( true ); } } /** * Retuns the current selection in the Exclusions table viewer. * * @return * the value that is selected in the Exclusions table viewer, or null. */ private String getSelectedValueExclusionsTable() { String value = null; IStructuredSelection selection = ( IStructuredSelection ) exclusionsTableViewer.getSelection(); if ( !selection.isEmpty() ) { Object element = selection.getFirstElement(); if ( element instanceof String ) { value = ( String ) element; } } return value; } /** * Opens the editor and adds the new Exclusion value to the list. */ private void addValueExclusionsTable() { Dn chopBase = subtreeSpecification.getBase(); if ( useLocalName && ( subentryDn != null ) ) { Dn suffix = subentryDn.getParent(); if ( !Dn.isNullOrEmpty( suffix ) ) { try { chopBase = chopBase.add( suffix ); } catch ( LdapInvalidDnException lide ) { // Do nothing } } } ExclusionDialog dialog = new ExclusionDialog( getShell(), connection, chopBase, "" ); //$NON-NLS-1$ if ( dialog.open() == TextDialog.OK && !SubtreeValueEditor.EMPTY.equals( dialog.getType() ) && !SubtreeValueEditor.EMPTY.equals( dialog.getDN() ) ) { String newValue = dialog.getType() + ": \"" + dialog.getDN() + "\""; //$NON-NLS-1$ //$NON-NLS-2$ exclusions.add( newValue ); exclusionsTableViewer.refresh(); validate(); } } /** * Opens the editor with the currently selected Exclusion * value and puts the modified value into the list. */ private void editValueExclusionsTable() { String oldValue = getSelectedValueExclusionsTable(); if ( oldValue != null ) { Dn chopBase = subtreeSpecification.getBase(); if ( useLocalName && ( subentryDn != null ) ) { Dn suffix = subentryDn.getParent(); if ( !Dn.isNullOrEmpty( suffix ) ) { try { chopBase = chopBase.add( suffix ); } catch ( LdapInvalidDnException lide ) { // Do nothing } } } ExclusionDialog dialog = new ExclusionDialog( getShell(), connection, chopBase, oldValue ); if ( dialog.open() == TextDialog.OK && !SubtreeValueEditor.EMPTY.equals( dialog.getType() ) && !SubtreeValueEditor.EMPTY.equals( dialog.getDN() ) ) { String newValue = dialog.getType() + ": \"" + dialog.getDN() + "\""; //$NON-NLS-1$ //$NON-NLS-2$ exclusions.remove( oldValue ); exclusions.add( newValue ); exclusionsTableViewer.refresh(); validate(); } } } /** * Deletes the currently selected Exclusion value from list. */ private void deleteValueExclusionsTable() { String value = getSelectedValueExclusionsTable(); if ( value != null ) { exclusions.remove( value ); exclusionsTableViewer.refresh(); validate(); } } /** * Gets the subtree specification value or null if canceled. * * @return the subtree specification value or null if canceled */ public String getSubtreeSpecificationValue() { return returnValue; } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/aciitemeditor/src/main/java/org/apache/directory/studio/aciitemeditor/valueeditors/AttributeTypeAndValueValueEditor.java
plugins/aciitemeditor/src/main/java/org/apache/directory/studio/aciitemeditor/valueeditors/AttributeTypeAndValueValueEditor.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.aciitemeditor.valueeditors; import org.apache.directory.studio.ldapbrowser.common.dialogs.TextDialog; import org.apache.directory.studio.ldapbrowser.core.model.IBrowserConnection; import org.apache.directory.studio.ldapbrowser.core.model.IValue; import org.apache.directory.studio.ldapbrowser.core.model.schema.Schema; import org.apache.directory.studio.valueeditors.AbstractDialogStringValueEditor; import org.eclipse.swt.widgets.Shell; /** * Implementation of IValueEditor for attribute type and value. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class AttributeTypeAndValueValueEditor extends AbstractDialogStringValueEditor { /** * {@inheritDoc} * * This implementation opens the AttributeTypeDialog. */ public boolean openDialog( Shell shell ) { Object value = getValue(); if ( value instanceof AttributeTypeAndValueValueEditorRawValueWrapper ) { AttributeTypeAndValueValueEditorRawValueWrapper wrapper = ( AttributeTypeAndValueValueEditorRawValueWrapper ) value; AttributeTypeAndValueDialog dialog = new AttributeTypeAndValueDialog( shell, wrapper.schema, wrapper.attributeType, wrapper.value ); if ( ( dialog.open() == TextDialog.OK ) && !EMPTY.equals( dialog.getAttributeType() ) && !EMPTY.equals( dialog.getValue() ) ) { setValue( dialog.getAttributeType() + '=' + dialog.getValue() ); return true; } } return false; } /** * {@inheritDoc} * * Returns an AttributeTypeAndValueValueEditorRawValueWrapper. */ public Object getRawValue( IValue value ) { if ( value != null ) { return getRawValue( value.getAttribute().getEntry().getBrowserConnection(), value.getStringValue() ); } return null; } private Object getRawValue( IBrowserConnection connection, Object value ) { Schema schema = null; if ( connection != null ) { schema = connection.getSchema(); } if ( ( schema == null ) || !( value instanceof String ) ) { return null; } String atavValue = ( String ) value; String[] atav = atavValue.split( "=", 2 ); //$NON-NLS-1$ String at = atav.length > 0 ? atav[0] : EMPTY; String v = atav.length > 1 ? atav[1] : EMPTY; AttributeTypeAndValueValueEditorRawValueWrapper wrapper = new AttributeTypeAndValueValueEditorRawValueWrapper( schema, at, v ); return wrapper; } /** * The AttributeTypeAndValueValueEditorRawValueWrapper is used to pass contextual * information to the opened AttributeTypeAndValueDialog. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ private class AttributeTypeAndValueValueEditorRawValueWrapper { /** * The schema, used in AttributeTypeDialog to build the list * with possible attribute types. */ private Schema schema; /** The attribute type, used as initial attribute type. */ private String attributeType; /** The value, used as initial value. */ private String value; /** * Creates a new instance of AttributeTypeAndValueValueEditorRawValueWrapper. * * @param schema the schema * @param attributeType the attribute type * @param value the value */ private AttributeTypeAndValueValueEditorRawValueWrapper( Schema schema, String attributeType, String value ) { super(); this.schema = schema; this.attributeType = attributeType; this.value = value; } } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/aciitemeditor/src/main/java/org/apache/directory/studio/aciitemeditor/valueeditors/SubtreeValueEditor.java
plugins/aciitemeditor/src/main/java/org/apache/directory/studio/aciitemeditor/valueeditors/SubtreeValueEditor.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.aciitemeditor.valueeditors; import org.apache.directory.api.ldap.model.name.Dn; import org.apache.directory.studio.ldapbrowser.common.dialogs.TextDialog; import org.apache.directory.studio.ldapbrowser.core.model.IBrowserConnection; import org.apache.directory.studio.ldapbrowser.core.model.IValue; import org.apache.directory.studio.valueeditors.AbstractDialogStringValueEditor; import org.apache.directory.studio.valueeditors.ValueEditorManager; import org.eclipse.swt.widgets.Shell; /** * ACI item editor specific value editor to edit the SubtreeSpecification. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class SubtreeValueEditor extends AbstractDialogStringValueEditor { private boolean refinementOrFilterVisible; private boolean useLocalName; /** * Default constructor, used by the {@link ValueEditorManager}. */ public SubtreeValueEditor() { this.refinementOrFilterVisible = true; this.useLocalName = true; } /** * Default constructor, used by the {@link ValueEditorManager}. * * @param refinementOrFilterVisible true if the refinement or filter widget should be visible * @param useLocalName true to use local name for the base */ public SubtreeValueEditor( boolean refinementOrFilterVisible, boolean useLocalName ) { this.refinementOrFilterVisible = refinementOrFilterVisible; this.useLocalName = useLocalName; } /** * @see org.apache.directory.studio.valueeditors.AbstractDialogValueEditor#openDialog(org.eclipse.swt.widgets.Shell) */ protected boolean openDialog( Shell shell ) { Object value = getValue(); if ( value instanceof SubtreeSpecificationValueWrapper ) { SubtreeSpecificationValueWrapper wrapper = ( SubtreeSpecificationValueWrapper ) value; SubtreeSpecificationDialog dialog = new SubtreeSpecificationDialog( shell, wrapper.connection, wrapper.subentryDn, wrapper.subtreeSpecification, refinementOrFilterVisible, useLocalName ); if ( dialog.open() == TextDialog.OK && dialog.getSubtreeSpecificationValue() != null ) { setValue( dialog.getSubtreeSpecificationValue() ); return true; } } return false; } /** * @see org.apache.directory.studio.valueeditors.AbstractDialogStringValueEditor#getRawValue( * org.apache.directory.studio.ldapbrowser.core.model.IValue) */ public Object getRawValue( IValue value ) { Object o = super.getRawValue( value ); if ( o instanceof String ) { IBrowserConnection connection = value.getAttribute().getEntry().getBrowserConnection(); Dn dn = value.getAttribute().getEntry().getDn(); return new SubtreeSpecificationValueWrapper( connection, dn, value.getStringValue() ); } return null; } /** * The SubtreeSpecificationValueWrapper is used to pass contextual * information to the opened SubtreeSpecificationDialog. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ private class SubtreeSpecificationValueWrapper { /** The connection, used in DnDialog to browse for an entry */ private IBrowserConnection connection; /** The subentry's Dn */ private Dn subentryDn; /** The subtreeSpecification */ private String subtreeSpecification; /** * Creates a new instance of SubtreeSpecificationValueWrapper. * * @param connection * the connection * @param subentryDn * the Dn of the subentry * @param subtreeSpecification * the subtreeSpecification */ private SubtreeSpecificationValueWrapper( IBrowserConnection connection, Dn subentryDn, String subtreeSpecification ) { this.connection = connection; this.subentryDn = subentryDn; this.subtreeSpecification = subtreeSpecification; } /** * {@inheritDoc} */ public String toString() { return subtreeSpecification == null ? "" : subtreeSpecification; //$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/aciitemeditor/src/main/java/org/apache/directory/studio/aciitemeditor/valueeditors/MaxValueCountValueEditor.java
plugins/aciitemeditor/src/main/java/org/apache/directory/studio/aciitemeditor/valueeditors/MaxValueCountValueEditor.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.aciitemeditor.valueeditors; import java.util.Arrays; import java.util.Collection; import java.util.regex.Matcher; import java.util.regex.Pattern; import org.apache.directory.studio.aciitemeditor.Activator; import org.apache.directory.studio.common.ui.widgets.BaseWidgetUtils; import org.apache.directory.studio.connection.ui.widgets.ExtendedContentAssistCommandAdapter; import org.apache.directory.studio.ldapbrowser.common.dialogs.TextDialog; import org.apache.directory.studio.ldapbrowser.common.widgets.ListContentProposalProvider; import org.apache.directory.studio.ldapbrowser.core.model.IBrowserConnection; import org.apache.directory.studio.ldapbrowser.core.model.IValue; import org.apache.directory.studio.ldapbrowser.core.model.schema.Schema; import org.apache.directory.studio.ldapbrowser.core.model.schema.SchemaUtils; import org.apache.directory.studio.valueeditors.AbstractDialogStringValueEditor; import org.eclipse.jface.dialogs.Dialog; import org.eclipse.jface.dialogs.IDialogConstants; import org.eclipse.jface.fieldassist.ComboContentAdapter; 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.Control; import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.widgets.Spinner; /** * ACI item editor specific value editor to edit the MaxValueCount protected item. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class MaxValueCountValueEditor extends AbstractDialogStringValueEditor { private static final String L_CURLY_TYPE = "{ type "; //$NON-NLS-1$ private static final String SEP_MAXCOUNT = ", maxCount "; //$NON-NLS-1$ private static final String R_CURLY = " }"; //$NON-NLS-1$ private static final String EMPTY = ""; //$NON-NLS-1$ /** * {@inheritDoc} * * This implementation opens the MaxValueCountDialog. */ public boolean openDialog( Shell shell ) { Object value = getValue(); if ( value instanceof MaxValueCountValueEditorRawValueWrapper ) { MaxValueCountValueEditorRawValueWrapper wrapper = ( MaxValueCountValueEditorRawValueWrapper ) value; MaxValueCountDialog dialog = new MaxValueCountDialog( shell, wrapper.schema, wrapper.type, wrapper.maxCount ); if ( dialog.open() == TextDialog.OK && !EMPTY.equals( dialog.getType() ) && dialog.getMaxCount() > -1 ) { setValue( L_CURLY_TYPE + dialog.getType() + SEP_MAXCOUNT + dialog.getMaxCount() + R_CURLY ); return true; } } return false; } /** * {@inheritDoc} * * Returns an AttributeTypeAndValueValueEditorRawValueWrapper. */ public Object getRawValue( IValue value ) { if ( value != null ) { return getRawValue( value.getAttribute().getEntry().getBrowserConnection(), value.getStringValue() ); } else { return null; } } private Object getRawValue( IBrowserConnection connection, Object value ) { Schema schema = null; if ( connection != null ) { schema = connection.getSchema(); } if ( schema == null || !( value instanceof String ) ) { return null; } String stringValue = ( String ) value; String type = EMPTY; int maxCount = 0; try { // for example: { type userPassword, maxCount 10 } Pattern pattern = Pattern.compile( "\\s*\\{\\s*type\\s*([^,]*),\\s*maxCount\\s*(\\d*)\\s*\\}\\s*" ); //$NON-NLS-1$ Matcher matcher = pattern.matcher( stringValue ); type = matcher.matches() ? matcher.group( 1 ) : EMPTY; maxCount = matcher.matches() ? Integer.valueOf( matcher.group( 2 ) ) : 0; } catch ( Exception e ) { } MaxValueCountValueEditorRawValueWrapper wrapper = new MaxValueCountValueEditorRawValueWrapper( schema, type, maxCount ); return wrapper; } /** * The MaxValueCountValueEditorRawValueWrapper is used to pass contextual * information to the opened MaxValueCountDialog. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ private class MaxValueCountValueEditorRawValueWrapper { /** * The schema, used in MaxValueCountDialog to build the list * with possible attribute types. */ private Schema schema; /** The attribute type, used as initial attribute type. */ private String type; /** The max count, used as initial value. */ private int maxCount; /** * Creates a new instance of AttributeTypeAndValueValueEditorRawValueWrapper. * * @param schema the schema * @param attributeType the attribute type * @param value the value */ private MaxValueCountValueEditorRawValueWrapper( Schema schema, String type, int maxCount ) { this.schema = schema; this.type = type; this.maxCount = maxCount; } } /** * This class provides a dialog to enter the MaxValueCount values. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ private class MaxValueCountDialog extends Dialog { /** The schema. */ private Schema schema; /** The initial attribute type. */ private String initialType; /** The initial max count. */ private int initialMaxCount; /** The attribute type combo. */ private Combo attributeTypeCombo; /** The max count spinner. */ private Spinner maxCountSpinner; /** The return attribute type. */ private String returnType; /** The return value. */ private int returnMaxCount; /** * Creates a new instance of AttributeTypeDialog. * * @param parentShell the parent shell * @param schema the schema * @param initialType the initial attribute type * @param initialMaxCount the initial max count */ public MaxValueCountDialog( Shell parentShell, Schema schema, String initialType, int initialMaxCount ) { super( parentShell ); super.setShellStyle( super.getShellStyle() | SWT.RESIZE ); this.initialType = initialType; this.initialMaxCount = initialMaxCount; this.schema = schema; this.returnType = null; this.returnMaxCount = -1; } /** * {@inheritDoc} */ protected void configureShell( Shell shell ) { super.configureShell( shell ); shell.setText( Messages.getString( "MaxValueCountValueEditor.title" ) ); //$NON-NLS-1$ shell.setImage( Activator.getDefault().getImage( Messages.getString( "MaxValueCountValueEditor.icon" ) ) ); //$NON-NLS-1$ } /** * {@inheritDoc} */ protected void okPressed() { returnType = attributeTypeCombo.getText(); returnMaxCount = maxCountSpinner.getSelection(); super.okPressed(); } /** * {@inheritDoc} */ protected Control createDialogArea( Composite parent ) { // create composite Composite composite = ( Composite ) super.createDialogArea( parent ); GridData gd = new GridData( GridData.FILL_BOTH ); gd.widthHint = convertHorizontalDLUsToPixels( IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH ); composite.setLayoutData( gd ); composite.setLayout( new GridLayout( 5, false ) ); BaseWidgetUtils.createLabel( composite, L_CURLY_TYPE, 1 ); // combo widget Collection<String> names = SchemaUtils.getNames( schema.getAttributeTypeDescriptions() ); String[] allAtNames = names.toArray( new String[names.size()] ); Arrays.sort( allAtNames ); // attribute combo with field decoration and content proposal attributeTypeCombo = BaseWidgetUtils.createCombo( composite, allAtNames, -1, 1 ); attributeTypeCombo.setText( initialType ); new ExtendedContentAssistCommandAdapter( attributeTypeCombo, new ComboContentAdapter(), new ListContentProposalProvider( attributeTypeCombo.getItems() ), null, null, true ); BaseWidgetUtils.createLabel( composite, SEP_MAXCOUNT, 1 ); maxCountSpinner = new Spinner( composite, SWT.BORDER ); maxCountSpinner.setMinimum( 0 ); maxCountSpinner.setMaximum( Integer.MAX_VALUE ); maxCountSpinner.setDigits( 0 ); maxCountSpinner.setIncrement( 1 ); maxCountSpinner.setPageIncrement( 100 ); maxCountSpinner.setSelection( initialMaxCount ); maxCountSpinner.setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) ); BaseWidgetUtils.createLabel( composite, R_CURLY, 1 ); applyDialogFont( composite ); return composite; } /** * Gets the attribute type. * * @return the attribute type, null if canceled */ public String getType() { return returnType; } /** * Gets the max count. * * @return the max count, -1 if canceled */ public int getMaxCount() { return returnMaxCount; } } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/ldapservers/src/main/java/org/apache/directory/studio/ldapservers/LdapServersManagerIOException.java
plugins/ldapservers/src/main/java/org/apache/directory/studio/ldapservers/LdapServersManagerIOException.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.ldapservers; /** * This exception can be raised when an error occurs when loading or saving * the servers to the store. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class LdapServersManagerIOException extends Exception { private static final long serialVersionUID = 1L; /** * Creates a new instance of ServersHandlerIOException. * * @param message * the detail message */ public LdapServersManagerIOException( String message ) { super( message ); } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/ldapservers/src/main/java/org/apache/directory/studio/ldapservers/LdapServersPlugin.java
plugins/ldapservers/src/main/java/org/apache/directory/studio/ldapservers/LdapServersPlugin.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.ldapservers; import java.io.IOException; import java.net.URL; 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.swt.graphics.Image; import org.eclipse.ui.plugin.AbstractUIPlugin; import org.osgi.framework.BundleContext; /** * The activator class controls the plug-in life cycle */ public class LdapServersPlugin extends AbstractUIPlugin { /** The shared plugin instance. */ private static LdapServersPlugin plugin; /** The plugin properties */ private PropertyResourceBundle properties; /** The LDAP Server Adapter Extensions Manager */ private LdapServerAdapterExtensionsManager ldapServerAdapterExtensionsManager = LdapServerAdapterExtensionsManager .getDefault(); /** The LDAP Servers Manager */ private LdapServersManager ldapServersManager = LdapServersManager.getDefault(); /** * The constructor */ public LdapServersPlugin() { plugin = this; } /** * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext) */ public void start( BundleContext context ) throws Exception { super.start( context ); // Loading the LDAP Server Adapters extensions ldapServerAdapterExtensionsManager.loadLdapServerAdapterExtensions(); // Loading the servers to the LDAP Servers Manager ldapServersManager.loadServersFromStore(); } /** * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext) */ public void stop( BundleContext context ) throws Exception { // Loading the servers to the LDAP Servers Manager ldapServersManager.saveServersToStore(); plugin = null; super.stop( context ); } /** * Returns the shared instance * * @return the shared instance */ public static LdapServersPlugin 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 in filesystem) * @return The image descriptor 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 in filesystem) * @return The SWT Image or null */ 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; } /** * 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.ldapservers", Status.OK, //$NON-NLS-1$ Messages.getString( "LdapServersPlugin.UnableGetPluginProperties" ), 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/ldapservers/src/main/java/org/apache/directory/studio/ldapservers/LdapServersManagerListener.java
plugins/ldapservers/src/main/java/org/apache/directory/studio/ldapservers/LdapServersManagerListener.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.ldapservers; import org.apache.directory.studio.ldapservers.model.LdapServer; /** * This interface represents a listener for the LDAP Servers Manager. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public interface LdapServersManagerListener { /** * This method is called when a server is added. * * @param server * the added server */ void serverAdded( LdapServer server ); /** * This method is called when a server is removed. * * @param server * the removed server */ void serverRemoved( LdapServer server ); /** * This method is called when a server is updated. * * @param server * the updated server */ void serverUpdated( LdapServer server ); }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/ldapservers/src/main/java/org/apache/directory/studio/ldapservers/LdapServersUtils.java
plugins/ldapservers/src/main/java/org/apache/directory/studio/ldapservers/LdapServersUtils.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.ldapservers; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.net.URL; import org.apache.commons.io.input.Tailer; import org.apache.commons.io.input.TailerListener; import org.apache.commons.io.input.TailerListenerAdapter; import org.apache.directory.studio.common.core.jobs.StudioProgressMonitor; import org.apache.directory.studio.common.ui.CommonUIUtils; import org.apache.directory.studio.ldapservers.model.LdapServer; import org.apache.directory.studio.ldapservers.model.LdapServerStatus; import org.apache.mina.util.AvailablePortFinder; import org.eclipse.core.runtime.FileLocator; import org.eclipse.core.runtime.IPath; import org.eclipse.debug.core.DebugEvent; import org.eclipse.debug.core.DebugPlugin; import org.eclipse.debug.core.IDebugEventSetListener; import org.eclipse.debug.core.ILaunch; import org.eclipse.debug.core.model.RuntimeProcess; import org.eclipse.osgi.util.NLS; import org.eclipse.ui.console.MessageConsole; import org.eclipse.ui.console.MessageConsoleStream; import org.osgi.framework.Bundle; /** * The helper class defines various utility methods for the LDAP Servers plugin. */ public class LdapServersUtils { /** The ID of the launch configuration custom object */ public static final String LAUNCH_CONFIGURATION_CUSTOM_OBJECT = "launchConfiguration"; //$NON-NLS-1$ /** The ID of the console printer custom object */ public static final String CONSOLE_PRINTER_CUSTOM_OBJECT = "consolePrinter"; //$NON-NLS-1$ /** * Runs the startup listener watchdog. * * @param server * the server * @param port * the port * @throws Exception */ public static void runStartupListenerWatchdog( LdapServer server, int port ) throws Exception { // If no protocol is enabled, we pass this and declare the server as started if ( port == 0 ) { return; } // Getting the current time long startTime = System.currentTimeMillis(); // Calculating the watch dog time final long watchDog = startTime + ( 1000 * 60 * 3 ); // 3 minutes // Looping until the end of the watchdog if the server is still 'starting' while ( ( System.currentTimeMillis() < watchDog ) && ( LdapServerStatus.STARTING == server.getStatus() ) ) { // Trying to see if the port is available if ( AvailablePortFinder.available( port ) ) { // The port is still available // We just wait one second before starting the test once again try { Thread.sleep( 1000 ); } catch ( InterruptedException e1 ) { // Nothing to do... } } else { // We set the state of the server to 'started'... server.setStatus( LdapServerStatus.STARTED ); // ... and we exit the thread return; } } // If, at the end of the watch dog, the state of the server is // still 'starting' then, we declare the server as 'stopped' if ( LdapServerStatus.STARTING == server.getStatus() ) { server.setStatus( LdapServerStatus.STOPPED ); } } /** * Starting the "terminate" listener thread. * * @param server * the server * @param launch * the launch */ public static void startTerminateListenerThread( final LdapServer server, final ILaunch launch ) { // Creating the thread Thread thread = new Thread() { public void run() { // Adding the listener DebugPlugin.getDefault().addDebugEventListener( new IDebugEventSetListener() { public void handleDebugEvents( DebugEvent[] events ) { // Looping on the debug events array for ( DebugEvent debugEvent : events ) { // We only care of event with kind equals to // 'terminate' if ( debugEvent.getKind() == DebugEvent.TERMINATE ) { // Getting the source of the debug event Object source = debugEvent.getSource(); if ( source instanceof RuntimeProcess ) { RuntimeProcess runtimeProcess = ( RuntimeProcess ) source; // Getting the associated launch ILaunch debugEventLaunch = runtimeProcess.getLaunch(); if ( debugEventLaunch.equals( launch ) ) { // The launch we had created is now terminated // The server is now stopped server.setStatus( LdapServerStatus.STOPPED ); // Removing the listener DebugPlugin.getDefault().removeDebugEventListener( this ); // ... and we exit the thread return; } } } } } } ); } }; // Starting the thread thread.start(); } /** * Starts the console printer thread. * * @param server * the server * @param serverLogsFile * the server logs file */ public static void startConsolePrinterThread( LdapServer server, File serverLogsFile ) { MessageConsole messageConsole = ConsolesManager.getDefault().getMessageConsole( server ); MessageConsoleStream messageStream = messageConsole.newMessageStream(); /* * DIRSTUDIO-1148: Tail the log file and update the console. * Tail from end only to avoid overwhelming the system in case the log file is large. */ TailerListener l = new TailerListenerAdapter() { public void handle( String line ) { messageStream.println( line ); }; }; Tailer tailer = Tailer.create( serverLogsFile, l, 1000L, true ); // Storing the tailer as a custom object in the LDAP Server for later use server.putCustomObject( CONSOLE_PRINTER_CUSTOM_OBJECT, tailer ); } /** * Stops the tailer thread. * * @param server * the server */ public static void stopConsolePrinterThread( LdapServer server ) { // Getting the console printer Tailer tailer = ( Tailer ) server .removeCustomObject( CONSOLE_PRINTER_CUSTOM_OBJECT ); if ( tailer != null ) { // Closing the console printer tailer.stop(); } } /** * Terminates the launch configuration. * * @param server * the server * @throws Exception */ public static void terminateLaunchConfiguration( LdapServer server ) throws Exception { // Getting the launch ILaunch launch = ( ILaunch ) server.removeCustomObject( LdapServersUtils.LAUNCH_CONFIGURATION_CUSTOM_OBJECT ); if ( launch != null ) { if ( ( !launch.isTerminated() ) ) { // Terminating the launch launch.terminate(); } } else { throw new Exception( Messages.getString( "LdapServersUtils.AssociatedLaunchConfigurationCouldNotBeFoundOrTerminated" ) ); //$NON-NLS-1$ } } /** * Verifies that the libraries folder exists and contains the jar files * needed to launch the server. * * @param bundle * the bundle * @param sourceLibrariesPath * the path to the source libraries * @param destinationLibrariesPath * the path to the destination libraries * @param libraries * the names of the libraries */ private static void verifyAndCopyLibraries( Bundle bundle, IPath sourceLibrariesPath, IPath destinationLibrariesPath, String[] libraries ) { // Destination libraries folder File destinationLibraries = destinationLibrariesPath.toFile(); if ( !destinationLibraries.exists() ) { destinationLibraries.mkdir(); } // Verifying and copying libraries (if needed) for ( String library : libraries ) { File destinationLibraryFile = destinationLibrariesPath.append( library ).toFile(); boolean newerFileExists = (bundle.getLastModified() > destinationLibraryFile.lastModified()); if ( !destinationLibraryFile.exists() || newerFileExists ) { try { copyResource( bundle, sourceLibrariesPath.append( library ), destinationLibraryFile ); } catch ( IOException e ) { CommonUIUtils.openErrorDialog( NLS.bind( Messages.getString( "LdapServersUtils.ErrorCopyingLibrary" ), //$NON-NLS-1$ new String[] { library, destinationLibraryFile.getAbsolutePath(), e.getMessage() } ) ); } } } } /** * Verifies that the libraries folder exists and contains the jar files * needed to launch the server. * * @param bundle * the bundle * @param sourceLibrariesPath * the path to the source libraries * @param destinationLibrariesPath * the path to the destination libraries * @param libraries * the names of the libraries * @param monitor the monitor * @param monitorTaskName the name of the task for the monitor */ public static void verifyAndCopyLibraries( Bundle bundle, IPath sourceLibrariesPath, IPath destinationLibrariesPath, String[] libraries, StudioProgressMonitor monitor, String monitorTaskName ) { // Creating the sub-task on the monitor monitor.subTask( monitorTaskName ); // Verifying and copying the libraries verifyAndCopyLibraries( bundle, sourceLibrariesPath, destinationLibrariesPath, libraries ); } /** * Copy the given resource. * * @param bundle * the bundle * @param resource * the path of the resource * @param destination * the destination * @throws IOException * if an error occurs when copying the jar file */ public static void copyResource( Bundle bundle, IPath resource, File destination ) throws IOException { // Getting he URL of the resource within the bundle URL resourceUrl = FileLocator.find( bundle, resource, null ); // Creating the input and output streams InputStream resourceInputStream = resourceUrl.openStream(); FileOutputStream resourceOutputStream = new FileOutputStream( destination ); // Copying the resource copyFile( resourceInputStream, resourceOutputStream ); // Closing the streams resourceInputStream.close(); resourceOutputStream.close(); } /** * Copies a file from the given streams. * * @param inputStream * the input stream * @param outputStream * the output stream * @throws IOException * if an error occurs when copying the file */ private static void copyFile( InputStream inputStream, OutputStream outputStream ) throws IOException { byte[] buf = new byte[1024]; int i = 0; while ( ( i = inputStream.read( buf ) ) != -1 ) { outputStream.write( buf, 0, i ); } } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/ldapservers/src/main/java/org/apache/directory/studio/ldapservers/LdapServersPluginConstants.java
plugins/ldapservers/src/main/java/org/apache/directory/studio/ldapservers/LdapServersPluginConstants.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.ldapservers; /** * Constants used in the LDAP Servers plugin. * Final reference -> class shouldn't be extended * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public final class LdapServersPluginConstants { /** * 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 LdapServersPluginConstants() { } /** The plug-in ID */ public static final String PLUGIN_ID = LdapServersPluginConstants.class.getPackage().getName(); /** The LDAP Adapters Extension Point ID */ public static final String LDAP_SERVER_ADAPTERS_EXTENSION_POINT = PLUGIN_ID + ".ldapServerAdapters"; //$NON-NLS-1$ // ------ // IMAGES // ------ public static final String IMG_FOLDER = "resources/icons/folder.gif"; //$NON-NLS-1$ public static final String IMG_SERVER_NEW = "resources/icons/server_new.gif"; //$NON-NLS-1$ public static final String IMG_SERVER_NEW_WIZARD = "resources/icons/server_new_wizard.png"; //$NON-NLS-1$ public static final String IMG_SERVER = "resources/icons/server.gif"; //$NON-NLS-1$ public static final String IMG_SERVER_STARTED = "resources/icons/server_started.gif"; //$NON-NLS-1$ public static final String IMG_SERVER_STARTING1 = "resources/icons/server_starting1.gif"; //$NON-NLS-1$ public static final String IMG_SERVER_STARTING2 = "resources/icons/server_starting2.gif"; //$NON-NLS-1$ public static final String IMG_SERVER_STARTING3 = "resources/icons/server_starting3.gif"; //$NON-NLS-1$ public static final String IMG_SERVER_STOPPED = "resources/icons/server_stopped.gif"; //$NON-NLS-1$ public static final String IMG_SERVER_STOPPING1 = "resources/icons/server_stopping1.gif"; //$NON-NLS-1$ public static final String IMG_SERVER_STOPPING2 = "resources/icons/server_stopping2.gif"; //$NON-NLS-1$ public static final String IMG_SERVER_STOPPING3 = "resources/icons/server_stopping3.gif"; //$NON-NLS-1$ public static final String IMG_START = "resources/icons/start.gif"; //$NON-NLS-1$ public static final String IMG_STOP = "resources/icons/stop.gif"; //$NON-NLS-1$ // -------- // COMMANDS // -------- public static final String CMD_DELETE = LdapServersPlugin.getDefault().getPluginProperties() .getString( "Cmd_Delete_id" ); //$NON-NLS-1$ public static final String CMD_NEW_SERVER = LdapServersPlugin.getDefault().getPluginProperties() .getString( "Cmd_NewServer_id" ); //$NON-NLS-1$ public static final String CMD_OPEN_CONFIGURATION = LdapServersPlugin.getDefault().getPluginProperties() .getString( "Cmd_OpenConfiguration_id" ); //$NON-NLS-1$ public static final String CMD_PROPERTIES = LdapServersPlugin.getDefault().getPluginProperties() .getString( "Cmd_Properties_id" ); //$NON-NLS-1$ public static final String CMD_RENAME = LdapServersPlugin.getDefault().getPluginProperties() .getString( "Cmd_Rename_id" ); //$NON-NLS-1$ public static final String CMD_START = LdapServersPlugin.getDefault().getPluginProperties() .getString( "Cmd_Start_id" ); //$NON-NLS-1$ public static final String CMD_STOP = LdapServersPlugin.getDefault().getPluginProperties() .getString( "Cmd_Stop_id" ); //$NON-NLS-1$ // -------------- // PROPERTY PAGES // -------------- public static final String PROP_SERVER_PROPERTY_PAGE = "org.apache.directory.studio.ldapservers.properties.ServerPropertyPage"; //$NON-NLS-1$ // ----- // VIEWS // ----- public static final String VIEW_SERVERS_VIEW = "org.apache.directory.studio.apacheds.serversView"; //$NON-NLS-1$ // -------- // CONTEXTS // -------- public static final String CONTEXTS_SERVERS_VIEW = LdapServersPlugin.getDefault().getPluginProperties() .getString( "Ctx_ServersView_id" ); //$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/ldapservers/src/main/java/org/apache/directory/studio/ldapservers/ConsolesManager.java
plugins/ldapservers/src/main/java/org/apache/directory/studio/ldapservers/ConsolesManager.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.ldapservers; import java.util.HashMap; import java.util.Map; import org.apache.directory.studio.ldapservers.model.LdapServer; import org.eclipse.ui.console.ConsolePlugin; import org.eclipse.ui.console.IConsole; import org.eclipse.ui.console.MessageConsole; /** * This class implements the consoles manager. * <p> * * It is used to store all the consoles associated to servers. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class ConsolesManager { /** The default instance */ private static ConsolesManager instance; /** The map of consoles identified by server ID */ private Map<LdapServer, MessageConsole> consolesMap; /** * Creates a new instance of ConsolesManager. */ private ConsolesManager() { // Initialization of the map consolesMap = new HashMap<LdapServer, MessageConsole>(); } /** * Gets the default consoles manager (singleton pattern). * * @return * the default consoles manager */ public static ConsolesManager getDefault() { if ( instance == null ) { instance = new ConsolesManager(); } return instance; } /** * Gets the message console associated with the if of the server. * * @param server * the server * @return * the associated message console. */ public MessageConsole getMessageConsole( LdapServer server ) { if ( consolesMap.containsKey( server ) ) { return consolesMap.get( server ); } else { MessageConsole messageConsole = new MessageConsole( server.getName() + " " + Messages.getString( "ConsolesManager.LdapServer" ), null ); //$NON-NLS-1$ //$NON-NLS-2$ // DIRSTUDIO-1148: limit the amount of characters shown in the console messageConsole.setWaterMarks( 70000, 80000 ); consolesMap.put( server, messageConsole ); ConsolePlugin.getDefault().getConsoleManager().addConsoles( new IConsole[] { messageConsole } ); return messageConsole; } } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/ldapservers/src/main/java/org/apache/directory/studio/ldapservers/LdapServersManager.java
plugins/ldapservers/src/main/java/org/apache/directory/studio/ldapservers/LdapServersManager.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.ldapservers; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.FileReader; import java.io.InputStream; import java.io.OutputStream; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import org.apache.directory.api.util.FileUtils; import org.apache.directory.studio.common.ui.CommonUIUtils; import org.apache.directory.studio.ldapservers.model.LdapServer; import org.eclipse.core.runtime.IPath; import org.eclipse.ui.IMemento; import org.eclipse.ui.XMLMemento; /** * This class implements the LDAP Servers Manager. * <p> * It is used to store all the LDAP Servers used and defined in the plugin. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class LdapServersManager { private static final String SERVERS = "servers"; //$NON-NLS-1$ /** The default instance */ private static LdapServersManager instance; /** The list of servers */ private List<LdapServer> serversList; /** The map of servers identified by ID */ private Map<String, LdapServer> serversIdMap; /** The listeners */ private List<LdapServersManagerListener> listeners; /** * Creates a new instance of ServersHandler. */ private LdapServersManager() { } /** * Gets the default servers handler (singleton pattern). * * @return * the default servers handler */ public static LdapServersManager getDefault() { if ( instance == null ) { instance = new LdapServersManager(); } return instance; } /** * Adds a server. * * @param server * the server to be added */ public void addServer( LdapServer server ) { addServer( server, true ); saveServersToStore(); } /** * Adds a server. * * @param server * the server to be added * @param notifyListeners * <code>true</code> if the listeners need to be notified, * <code>false</code> if not. */ private void addServer( LdapServer server, boolean notifyListeners ) { if ( !serversList.contains( server ) ) { // Adding the server serversList.add( server ); serversIdMap.put( server.getId(), server ); // Notifying listeners if ( notifyListeners ) { for ( LdapServersManagerListener listener : listeners.toArray( new LdapServersManagerListener[0] ) ) { listener.serverAdded( server ); } } } } /** * Removes a server. * * @param server * the server to be removed */ public void removeServer( LdapServer server ) { removeServer( server, true ); saveServersToStore(); } /** * Removes a server. * * @param server * the server to be removed * @param notifyListeners * <code>true</code> if the listeners need to be notified, * <code>false</code> if not. */ private void removeServer( LdapServer server, boolean notifyListeners ) { if ( serversList.contains( server ) ) { // Removing the server serversList.remove( server ); serversIdMap.remove( server.getId() ); // Notifying listeners if ( notifyListeners ) { for ( LdapServersManagerListener listener : listeners.toArray( new LdapServersManagerListener[0] ) ) { listener.serverRemoved( server ); } } } } /** * Indicates if the server handler contains the given server. * * @param server * the server * @return * <code>true</code> if the server hander contains the given server, * <code>false</code> if not */ public boolean containsServer( LdapServer server ) { return serversList.contains( server ); } /** * Adds a listener to the servers handler. * * @param listener * the listener to add */ public void addListener( LdapServersManagerListener listener ) { if ( !listeners.contains( listener ) ) { listeners.add( listener ); } } /** * Removes a listener to the servers handler. * * @param listener * the listener to remove */ public void removeListener( LdapServersManagerListener listener ) { if ( listeners.contains( listener ) ) { listeners.remove( listener ); } } /** * Loads the server from the file store. */ public void loadServersFromStore() { // Initializing lists and maps serversList = new ArrayList<LdapServer>(); serversIdMap = new HashMap<String, LdapServer>(); listeners = new ArrayList<LdapServersManagerListener>(); File store = getServersStorePath().toFile(); File tempStore = getServersStoreTempPath().toFile(); boolean loadFailed = false; String exceptionMessage = ""; //$NON-NLS-1$ // We try to load the servers file if ( store.exists() ) { try { InputStream inputStream = new FileInputStream( store ); List<LdapServer> servers = LdapServersManagerIO.read( inputStream ); for ( LdapServer server : servers ) { addServer( server, false ); } return; } catch ( FileNotFoundException e ) { loadFailed = true; exceptionMessage = e.getMessage(); } catch ( LdapServersManagerIOException e ) { loadFailed = true; exceptionMessage = e.getMessage(); } if ( loadFailed ) { if ( tempStore.exists() ) { // If something went wrong, we try to load the temp servers file try { InputStream inputStream = new FileInputStream( tempStore ); List<LdapServer> servers = LdapServersManagerIO.read( inputStream ); for ( LdapServer server : servers ) { addServer( server, false ); } return; } catch ( Exception e ) { CommonUIUtils.openErrorDialog( Messages.getString( "LdapServersManager.ErrorLoadingServer" ) //$NON-NLS-1$ + e.getMessage() ); } } else { CommonUIUtils.openErrorDialog( Messages.getString( "LdapServersManager.ErrorLoadingServer" ) //$NON-NLS-1$ + exceptionMessage ); } } } } /** * Saves the server to the file store. */ public void saveServersToStore() { File store = getServersStorePath().toFile(); File tempStore = getServersStoreTempPath().toFile(); boolean saveFailed = false; try { // Saving the servers to the temp servers file OutputStream outputStream = new FileOutputStream( tempStore ); LdapServersManagerIO.write( serversList, outputStream ); // Copying the temp servers file to the final location String content = FileUtils.readFileToString( tempStore, "UTF-8" ); //$NON-NLS-1$ FileUtils.writeStringToFile( store, content, "UTF-8" ); //$NON-NLS-1$ } catch ( Exception e ) { saveFailed = true; } if ( saveFailed ) { // If an error occurs when saving to the temp servers file or // when copying the temp servers file to the final location, // we try to save the servers directly to the final location. try { // Saving the servers to the temp servers file OutputStream outputStream = new FileOutputStream( store ); LdapServersManagerIO.write( serversList, outputStream ); outputStream.close(); } catch ( Exception e ) { CommonUIUtils .openErrorDialog( Messages.getString( "LdapServersManager.ErrorLoadingServer" ) + e.getMessage() ); //$NON-NLS-1$ } } } /** * Gets the path to the server file. * * @return * the path to the server file. */ private IPath getServersStorePath() { return LdapServersPlugin.getDefault().getStateLocation().append( "ldapServers.xml" ); //$NON-NLS-1$ } /** * Gets the path to the server temp file. * * @return * the path to the server temp file. */ private IPath getServersStoreTempPath() { return LdapServersPlugin.getDefault().getStateLocation().append( "ldapServers-temp.xml" ); //$NON-NLS-1$ } /** * Indicates if the given is available (i.e. not already taken by another * server). * * @param name * the name * @return * <code>true</code> if the name is available, <code>false</code> if * not */ public boolean isNameAvailable( String name ) { for ( LdapServer serverInstance : serversList ) { if ( serverInstance.getName().equalsIgnoreCase( name ) ) { return false; } } return true; } /** * Gets the servers list. * * @return * the servers list. */ public List<LdapServer> getServersList() { return serversList; } /** * Gets the server associated with the given id. * * @return * the server associated witht the given id. */ public LdapServer getServerById( String id ) { return serversIdMap.get( id ); } /** * Get the path to the servers folder. * * @return * the path to the server folder */ public static IPath getServersFolder() { return LdapServersPlugin.getDefault().getStateLocation().append( SERVERS ); } /** * Gets the path to the server's folder. * * @param server * the server * @return * the path to the server's folder */ public static IPath getServerFolder( LdapServer server ) { if ( server != null ) { return getServersFolder().append( server.getId() ); } return null; } /** * Creates a new server folder for the given id. * * @param id * the id of the server */ public static void createNewServerFolder( LdapServer server ) { if ( server != null ) { // Creating if needed the 'servers' folder File serversFolder = getServersFolder().toFile(); if ( !serversFolder.exists() ) { serversFolder.mkdir(); } // Creating the specific server folder File serverFolder = getServerFolder( server ).toFile(); if ( !serverFolder.exists() ) { serverFolder.mkdir(); } } } /** * Gets the memento for the given server. * * @param server * the server * @return * the associated memento */ public static IMemento getMementoForServer( LdapServer server ) { try { if ( server != null ) { // Creating the File of the memento (if needed) File mementoFile = getServerFolder( server ).append( "memento.xml" ).toFile(); //$NON-NLS-1$ if ( !mementoFile.exists() ) { mementoFile.createNewFile(); } // Getting a (read-only) memento from the File XMLMemento readMemento = XMLMemento.createReadRoot( new FileReader( mementoFile ) ); // Converting the read memento to a writable memento XMLMemento memento = XMLMemento.createWriteRoot( "memento" ); //$NON-NLS-1$ memento.putMemento( readMemento ); return memento; } return null; } catch ( Exception e ) { 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/ldapservers/src/main/java/org/apache/directory/studio/ldapservers/Messages.java
plugins/ldapservers/src/main/java/org/apache/directory/studio/ldapservers/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.ldapservers; 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/ldapservers/src/main/java/org/apache/directory/studio/ldapservers/LdapServerAdapterExtensionsManager.java
plugins/ldapservers/src/main/java/org/apache/directory/studio/ldapservers/LdapServerAdapterExtensionsManager.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.ldapservers; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import org.apache.directory.studio.ldapservers.model.LdapServerAdapter; import org.apache.directory.studio.ldapservers.model.LdapServerAdapterExtension; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IConfigurationElement; import org.eclipse.core.runtime.Platform; import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.ui.plugin.AbstractUIPlugin; /** * This class implements the LDAP Server Extensions Manager. * <p> * It is used to store all the LDAP Server Extensions. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class LdapServerAdapterExtensionsManager { // Attributes names used in 'plugin.xml' file public static final String ID_ATTR = "id"; //$NON-NLS-1$ public static final String NAME_ATTR = "name"; //$NON-NLS-1$ public static final String VERSION_ATTR = "version"; //$NON-NLS-1$ public static final String VENDOR_ATTR = "vendor"; //$NON-NLS-1$ public static final String CLASS_ATTR = "class"; //$NON-NLS-1$ public static final String DESCRIPTION_ATTR = "description"; //$NON-NLS-1$ public static final String ICON_ATTR = "icon"; //$NON-NLS-1$ public static final String CONFIGURATION_PAGE_ATTR = "configurationPage"; //$NON-NLS-1$ public static final String OPEN_CONFIGURATION_ACTION_ENABLED_ATTR = "openConfigurationActionEnabled"; //$NON-NLS-1$ /** The default instance */ private static LdapServerAdapterExtensionsManager instance; /** The list and map for LDAP Server Adapter Extensions */ private List<LdapServerAdapterExtension> ldapServerAdapterExtensionsList; /** The map and map for LDAP Server Adapter Extensions */ private Map<String, LdapServerAdapterExtension> ldapServerAdapterExtensionsByIdMap; /** * Creates a new instance of LdapServerAdapterExtensionsManager. */ private LdapServerAdapterExtensionsManager() { } /** * Loads the LDAP Server Adapter Extensions. */ public void loadLdapServerAdapterExtensions() { // Initializing the list and map for LDAP Server Adapter Extensions ldapServerAdapterExtensionsList = new ArrayList<LdapServerAdapterExtension>(); ldapServerAdapterExtensionsByIdMap = new HashMap<String, LdapServerAdapterExtension>(); // Getting members of LDAP Server Adapters Extension Point IConfigurationElement[] members = Platform.getExtensionRegistry() .getExtensionPoint( LdapServersPluginConstants.LDAP_SERVER_ADAPTERS_EXTENSION_POINT ) .getConfigurationElements(); // Creating an object associated with each member for ( IConfigurationElement member : members ) { // Creating the LdapServerAdapterExtension object container LdapServerAdapterExtension ldapServerAdapterExtension = new LdapServerAdapterExtension(); // Getting the ID of the extending plugin String extendingPluginId = member.getDeclaringExtension().getNamespaceIdentifier(); // Setting each parameter to the LDAP Server Adapter Extension ldapServerAdapterExtension.setExtensionPointConfiguration( member ); ldapServerAdapterExtension.setId( member.getAttribute( ID_ATTR ) ); ldapServerAdapterExtension.setName( member.getAttribute( NAME_ATTR ) ); ldapServerAdapterExtension.setVersion( member.getAttribute( VERSION_ATTR ) ); ldapServerAdapterExtension.setVendor( member.getAttribute( VENDOR_ATTR ) ); ldapServerAdapterExtension.setClassName( member.getAttribute( CLASS_ATTR ) ); try { ldapServerAdapterExtension.setInstance( ( LdapServerAdapter ) member .createExecutableExtension( CLASS_ATTR ) ); } catch ( CoreException e ) { // Will never happen } ldapServerAdapterExtension.setDescription( member.getAttribute( DESCRIPTION_ATTR ) ); String iconPath = member.getAttribute( ICON_ATTR ); if ( iconPath != null ) { ImageDescriptor icon = AbstractUIPlugin.imageDescriptorFromPlugin( extendingPluginId, iconPath ); if ( icon == null ) { icon = ImageDescriptor.getMissingImageDescriptor(); } ldapServerAdapterExtension.setIcon( icon ); } ldapServerAdapterExtension.setConfigurationPageClassName( member.getAttribute( CONFIGURATION_PAGE_ATTR ) ); String openConfigurationActionEnabled = member.getAttribute( OPEN_CONFIGURATION_ACTION_ENABLED_ATTR ); if ( openConfigurationActionEnabled != null ) { ldapServerAdapterExtension.setOpenConfigurationActionEnabled( Boolean .parseBoolean( openConfigurationActionEnabled ) ); } else { // Enabled by default ldapServerAdapterExtension.setOpenConfigurationActionEnabled( true ); } ldapServerAdapterExtensionsList.add( ldapServerAdapterExtension ); ldapServerAdapterExtensionsByIdMap.put( ldapServerAdapterExtension.getId(), ldapServerAdapterExtension ); } } /** * Gets the default {@link LdapServerAdapterExtensionsManager} (singleton pattern). * * @return * the default {@link LdapServerAdapterExtensionsManager} */ public static LdapServerAdapterExtensionsManager getDefault() { if ( instance == null ) { instance = new LdapServerAdapterExtensionsManager(); } return instance; } /** * Gets the LDAP Server Adapter Extensions list. * * @return * the LDAP Server Adapter Extensions list. */ public List<LdapServerAdapterExtension> getLdapServerAdapterExtensions() { return ldapServerAdapterExtensionsList; } /** * Gets the LDAP Server Adapter Extension associated with the given id. * * @return * the LDAP Server Adapter Extension associated with the given id. */ public LdapServerAdapterExtension getLdapServerAdapterExtensionById( String id ) { return ldapServerAdapterExtensionsByIdMap.get( id ); } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/ldapservers/src/main/java/org/apache/directory/studio/ldapservers/LdapServersManagerIO.java
plugins/ldapservers/src/main/java/org/apache/directory/studio/ldapservers/LdapServersManagerIO.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.ldapservers; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.util.ArrayList; import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Map.Entry; import java.util.Set; import org.apache.directory.studio.ldapservers.model.LdapServer; import org.apache.directory.studio.ldapservers.model.LdapServerAdapterExtension; import org.apache.directory.studio.ldapservers.model.UnknownLdapServerAdapterExtension; import org.dom4j.Attribute; import org.dom4j.Document; import org.dom4j.DocumentException; import org.dom4j.DocumentHelper; import org.dom4j.Element; import org.dom4j.io.OutputFormat; import org.dom4j.io.SAXReader; import org.dom4j.io.XMLWriter; /** * This class is used to read/write the 'servers.xml' file. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class LdapServersManagerIO { // XML tags and attributes private static final String LDAP_SERVERS_TAG = "ldapServers"; //$NON-NLS-1$ private static final String LDAP_SERVER_TAG = "ldapServer"; //$NON-NLS-1$ private static final String ID_ATTRIBUTE = "id"; //$NON-NLS-1$ private static final String NAME_ATTRIBUTE = "name"; //$NON-NLS-1$ private static final String ADAPTER_ID_ATTRIBUTE = "adapterId"; //$NON-NLS-1$ private static final String ADAPTER_NAME_ATTRIBUTE = "adapterName"; //$NON-NLS-1$ private static final String ADAPTER_VENDOR_ATTRIBUTE = "adapterVendor"; //$NON-NLS-1$ private static final String ADAPTER_VERSION_ATTRIBUTE = "adapterVersion"; //$NON-NLS-1$ private static final String CONFIGURATION_PARAMETERS_TAG = "configurationParameters"; //$NON-NLS-1$ private static final String ENTRY_TAG = "entry"; //$NON-NLS-1$ private static final String KEY_ATTRIBUTE = "key"; //$NON-NLS-1$ private static final String TYPE_ATTRIBUTE = "type"; //$NON-NLS-1$ private static final String VALUE_ATTRIBUTE = "value"; //$NON-NLS-1$ /** * Reads the given input stream. * * @param stream * the input stream * @return * the list of LDAP Servers found in the input stream * @throws LdapServersManagerIOException */ public static List<LdapServer> read( InputStream stream ) throws LdapServersManagerIOException { List<LdapServer> servers = new ArrayList<LdapServer>(); SAXReader saxReader = new SAXReader(); Document document = null; try { document = saxReader.read( stream ); } catch ( DocumentException e ) { throw new LdapServersManagerIOException( e.getMessage() ); } Element rootElement = document.getRootElement(); if ( !rootElement.getName().equals( LDAP_SERVERS_TAG ) ) { throw new LdapServersManagerIOException( Messages.getString( "LdapServersManagerIO.ErrorNotValidServersFile" ) ); //$NON-NLS-1$ } for ( Iterator<?> i = rootElement.elementIterator( LDAP_SERVER_TAG ); i.hasNext(); ) { servers.add( readLdapServer( ( Element ) i.next() ) ); } return servers; } /** * Reads an LDAP Server element. * * @param element * the element * @return * the corresponding {@link LdapServer} */ private static LdapServer readLdapServer( Element element ) { LdapServer server = new LdapServer(); // ID Attribute idAttribute = element.attribute( ID_ATTRIBUTE ); if ( idAttribute != null ) { server.setId( idAttribute.getValue() ); } // Name Attribute nameAttribute = element.attribute( NAME_ATTRIBUTE ); if ( nameAttribute != null ) { server.setName( nameAttribute.getValue() ); } // Adapter ID Attribute adapterIdAttribute = element.attribute( ADAPTER_ID_ATTRIBUTE ); if ( adapterIdAttribute != null ) { // Getting the id String adapterId = adapterIdAttribute.getValue(); // Looking for the correct LDAP Server Adapter Extension object LdapServerAdapterExtension ldapServerAdapterExtension = LdapServerAdapterExtensionsManager.getDefault() .getLdapServerAdapterExtensionById( adapterId ); if ( ldapServerAdapterExtension != null ) { // The Adapter Extension has been found // Assigning it to the server server.setLdapServerAdapterExtension( ldapServerAdapterExtension ); } else { // The Adapter Extension has not been found // Creating an "unknown" Adapter Extension UnknownLdapServerAdapterExtension unknownLdapServerAdapterExtension = new UnknownLdapServerAdapterExtension(); // Adapter Id unknownLdapServerAdapterExtension.setId( adapterId ); // Adapter Name Attribute adapterNameAttribute = element.attribute( ADAPTER_NAME_ATTRIBUTE ); if ( adapterNameAttribute != null ) { unknownLdapServerAdapterExtension.setName( adapterNameAttribute.getValue() ); } // Adapter Vendor Attribute adapterVendorAttribute = element.attribute( ADAPTER_VENDOR_ATTRIBUTE ); if ( adapterVendorAttribute != null ) { unknownLdapServerAdapterExtension.setVendor( adapterVendorAttribute.getValue() ); } // Adapter Version Attribute adapterVersionAttribute = element.attribute( ADAPTER_VERSION_ATTRIBUTE ); if ( adapterVersionAttribute != null ) { unknownLdapServerAdapterExtension.setVersion( adapterVersionAttribute.getValue() ); } // Assigning the "unknown" Adapter Extension to the server server.setLdapServerAdapterExtension( unknownLdapServerAdapterExtension ); } } else { // TODO No Adapter ID, throw an error ? } // Configuration Parameters Element configurationParametersElement = element.element( CONFIGURATION_PARAMETERS_TAG ); if ( configurationParametersElement != null ) { for ( Iterator<?> i = configurationParametersElement.elementIterator( ENTRY_TAG ); i.hasNext(); ) { readConfigurationParameter( server, ( Element ) i.next() ); } } return server; } /** * Reads a configuration parameter. * * @param server the server * @param element the element */ private static void readConfigurationParameter( LdapServer server, Element element ) { // Key Attribute keyAttribute = element.attribute( KEY_ATTRIBUTE ); String key = null; if ( keyAttribute != null ) { key = keyAttribute.getValue(); // Value Attribute valueAttribute = element.attribute( VALUE_ATTRIBUTE ); String value = null; if ( valueAttribute != null ) { value = valueAttribute.getValue(); } // Type Attribute typeAttribute = element.attribute( TYPE_ATTRIBUTE ); String type = null; if ( typeAttribute != null ) { type = typeAttribute.getValue(); } // Integer value if ( ( type != null ) && ( type.equalsIgnoreCase( Integer.class.getCanonicalName() ) ) ) { server.putConfigurationParameter( key, Integer.parseInt( value ) ); } // Boolean value else if ( ( type != null ) && ( type.equalsIgnoreCase( Boolean.class.getCanonicalName() ) ) ) { server.putConfigurationParameter( key, Boolean.parseBoolean( value ) ); } // String value (default type) else { server.putConfigurationParameter( key, value ); } } } /** * Writes the list of servers to the given stream. * * @param servers * the servers * @param outputStream * the output stream * @throws IOException * if an error occurs when writing to the stream */ public static void write( List<LdapServer> servers, OutputStream outputStream ) throws IOException { // Creating the Document Document document = DocumentHelper.createDocument(); // Creating the root element Element root = document.addElement( LDAP_SERVERS_TAG ); if ( servers != null ) { for ( LdapServer server : servers ) { addLdapServer( server, root ); } } // Writing the file to the stream OutputFormat outformat = OutputFormat.createPrettyPrint(); outformat.setEncoding( "UTF-8" ); //$NON-NLS-1$ XMLWriter writer = new XMLWriter( outputStream, outformat ); writer.write( document ); writer.flush(); } /** * Adds the XML representation of the LDAP Server to the given parent. * * @param server * the server * @param parent * the parent element */ private static void addLdapServer( LdapServer server, Element parent ) { // Server element Element serverElement = parent.addElement( LDAP_SERVER_TAG ); // ID serverElement.addAttribute( ID_ATTRIBUTE, server.getId() ); // Name serverElement.addAttribute( NAME_ATTRIBUTE, server.getName() ); // Adapter ID serverElement.addAttribute( ADAPTER_ID_ATTRIBUTE, server.getLdapServerAdapterExtension().getId() ); // Adapter Name serverElement.addAttribute( ADAPTER_NAME_ATTRIBUTE, server.getLdapServerAdapterExtension().getName() ); // Adapter Vendor serverElement.addAttribute( ADAPTER_VENDOR_ATTRIBUTE, server.getLdapServerAdapterExtension().getVendor() ); // Adapter Version serverElement.addAttribute( ADAPTER_VERSION_ATTRIBUTE, server.getLdapServerAdapterExtension().getVersion() ); // Configuration Parameters Map<String, Object> configurationParametersMap = server.getConfigurationParameters(); if ( ( configurationParametersMap != null ) && ( configurationParametersMap.size() > 0 ) ) { addConfigurationParameters( configurationParametersMap, serverElement ); } } /** * Adds the XML representation of the configuration elements to the given parent. * * @param map the configuration elements map * @param element the parent element */ private static void addConfigurationParameters( Map<String, Object> map, Element parent ) { // Configuration Parameters element Element configurationParametersElement = parent.addElement( CONFIGURATION_PARAMETERS_TAG ); // Get the keys of the map Set<Entry<String, Object>> entriesSet = map.entrySet(); for ( Entry<String, Object> entry : entriesSet ) { // Entry element Element entryElement = configurationParametersElement.addElement( ENTRY_TAG ); // Key entryElement.addAttribute( KEY_ATTRIBUTE, entry.getKey() ); // Value Object value = entry.getValue(); entryElement.addAttribute( VALUE_ATTRIBUTE, value.toString() ); // Type if ( value.getClass() != String.class ) { entryElement.addAttribute( TYPE_ATTRIBUTE, value.getClass().getCanonicalName() ); } } } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/ldapservers/src/main/java/org/apache/directory/studio/ldapservers/jobs/StopLdapServerRunnable.java
plugins/ldapservers/src/main/java/org/apache/directory/studio/ldapservers/jobs/StopLdapServerRunnable.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.ldapservers.jobs; import org.apache.directory.studio.common.core.jobs.StudioProgressMonitor; import org.apache.directory.studio.common.core.jobs.StudioRunnableWithProgress; import org.apache.directory.studio.ldapservers.model.LdapServer; import org.apache.directory.studio.ldapservers.model.LdapServerAdapter; import org.apache.directory.studio.ldapservers.model.LdapServerAdapterExtension; import org.apache.directory.studio.ldapservers.model.LdapServerStatus; import org.eclipse.core.runtime.jobs.Job; import org.eclipse.osgi.util.NLS; /** * This class implements a {@link Job} that is used to stop an LDAP Server. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class StopLdapServerRunnable implements StudioRunnableWithProgress { /** The server */ private LdapServer server; /** * Creates a new instance of StartLdapServerRunnable. * * @param server * the LDAP Server */ public StopLdapServerRunnable( LdapServer server ) { this.server = server; } /** * {@inheritDoc} */ public String getErrorMessage() { return NLS.bind( Messages.getString( "StopLdapServerRunnable.UnableToStopServer" ), new String[] //$NON-NLS-1$ { server.getName() } ); } /** * {@inheritDoc} */ public Object[] getLockedObjects() { return new Object[] { server }; } /** * {@inheritDoc} */ public String getName() { return NLS.bind( Messages.getString( "StopLdapServerRunnable.StopServer" ), new String[] { server.getName() } ); //$NON-NLS-1$; } /** * {@inheritDoc} */ public void run( StudioProgressMonitor monitor ) { // Setting the status on the server to 'stopping' server.setStatus( LdapServerStatus.STOPPING ); // Starting a new watchdog thread StopLdapServerWatchDogThread.runNewWatchDogThread( server ); // Launching the 'stop()' method of the LDAP Server Adapter LdapServerAdapterExtension ldapServerAdapterExtension = server.getLdapServerAdapterExtension(); if ( ldapServerAdapterExtension != null ) { LdapServerAdapter ldapServerAdapter = ldapServerAdapterExtension.getInstance(); if ( ldapServerAdapter != null ) { try { ldapServerAdapter.stop( server, monitor ); } catch ( Exception e ) { // Setting the server as started server.setStatus( LdapServerStatus.STARTED ); // Reporting the error to the monitor monitor.reportError( 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/ldapservers/src/main/java/org/apache/directory/studio/ldapservers/jobs/StudioLdapServerJob.java
plugins/ldapservers/src/main/java/org/apache/directory/studio/ldapservers/jobs/StudioLdapServerJob.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.ldapservers.jobs; import org.apache.directory.studio.common.core.jobs.StudioJob; import org.apache.directory.studio.common.core.jobs.StudioRunnableWithProgress; import org.apache.directory.studio.ldapservers.model.LdapServer; /** * This class implements a {@link Job} that is used for {@link StudioRunnableWithProgress} runnables on LDAP Servers. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class StudioLdapServerJob extends StudioJob<StudioRunnableWithProgress> { /** * Creates a new instance of StudioLdapServerJob. * * @param runnables the runnables to run */ public StudioLdapServerJob( StudioRunnableWithProgress... runnables ) { super( runnables ); } /** * {@inheritDoc} */ @Override protected String[] getLockIdentifiers( Object... objects ) { String[] identifiers = new String[objects.length]; for ( int i = 0; i < identifiers.length; i++ ) { Object o = objects[i]; if ( o instanceof LdapServer ) { identifiers[i] = getLockIdentifier( ( LdapServer ) o ); } else { identifiers[i] = getLockIdentifier( objects[i] ); } } return identifiers; } /** * Gets the lock identifier for an {@link LdapServer} object. * * @param server * the server * @return * the lock identifier for the server object */ private String getLockIdentifier( LdapServer server ) { return server.getId(); } /** * Gets the generic lock identifier for an object. * * @param object * the object * @return * the lock identifier for the object */ private String getLockIdentifier( Object object ) { return ( object != null ? object.toString() : "null" ); //$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/ldapservers/src/main/java/org/apache/directory/studio/ldapservers/jobs/DeleteLdapServerRunnable.java
plugins/ldapservers/src/main/java/org/apache/directory/studio/ldapservers/jobs/DeleteLdapServerRunnable.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.ldapservers.jobs; import java.io.File; import org.apache.directory.studio.common.core.jobs.StudioProgressMonitor; import org.apache.directory.studio.common.core.jobs.StudioRunnableWithProgress; import org.apache.directory.studio.ldapservers.LdapServersManager; import org.apache.directory.studio.ldapservers.model.LdapServer; import org.apache.directory.studio.ldapservers.model.LdapServerAdapter; import org.apache.directory.studio.ldapservers.model.LdapServerStatus; import org.eclipse.core.runtime.jobs.Job; import org.eclipse.osgi.util.NLS; /** * This class implements a {@link Job} that is used to delete an LDAP Server. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class DeleteLdapServerRunnable implements StudioRunnableWithProgress { /** The server */ private LdapServer server; /** * Creates a new instance of StartLdapServerRunnable. * * @param server * the LDAP Server */ public DeleteLdapServerRunnable( LdapServer server ) { super(); this.server = server; } /** * {@inheritDoc} */ public String getErrorMessage() { return NLS.bind( Messages.getString( "DeleteLdapServerRunnable.UnableToDeleteServer" ), new String[] //$NON-NLS-1$ { server.getName() } ); } /** * {@inheritDoc} */ public Object[] getLockedObjects() { return new Object[] { server }; } /** * {@inheritDoc} */ public String getName() { return NLS.bind( Messages.getString( "DeleteLdapServerRunnable.DeleteServer" ), new String[] { server.getName() } ); //$NON-NLS-1$ } /** * {@inheritDoc} */ public void run( StudioProgressMonitor monitor ) { // Storing the started status of the server boolean serverStarted = server.getStatus() == LdapServerStatus.STARTED; try { // Checking if the server is running // If yes, we need to shut it down before removing its data if ( serverStarted ) { // Creating, scheduling and waiting on the job to stop the server StudioLdapServerJob job = new StudioLdapServerJob( new StopLdapServerRunnable( server ) ); job.schedule(); job.join(); } // Removing the server LdapServersManager.getDefault().removeServer( server ); // Deleting the associated directory on disk deleteDirectory( LdapServersManager.getServerFolder( server ).toFile() ); // Letting the LDAP Server Adapter finish the deletion of the server LdapServerAdapter ldapServerAdapter = server.getLdapServerAdapterExtension().getInstance(); if ( ldapServerAdapter != null ) { ldapServerAdapter.delete( server, monitor ); } } catch ( InterruptedException e ) { // Nothing to do } catch ( Exception e ) { if ( serverStarted ) { // Setting the server as started server.setStatus( LdapServerStatus.STARTED ); } else { // Setting the server as stopped server.setStatus( LdapServerStatus.STOPPED ); } // Reporting the error to the monitor monitor.reportError( e ); } } /** * Deletes the given directory * * @param path * the directory * @return * <code>true</code> if and only if the directory is * successfully deleted; <code>false</code> otherwise */ private boolean deleteDirectory( File path ) { if ( path.exists() ) { File[] files = path.listFiles(); for ( int i = 0; i < files.length; i++ ) { if ( files[i].isDirectory() ) { deleteDirectory( files[i] ); } else { files[i].delete(); } } } return ( path.delete() ); } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/ldapservers/src/main/java/org/apache/directory/studio/ldapservers/jobs/Messages.java
plugins/ldapservers/src/main/java/org/apache/directory/studio/ldapservers/jobs/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.ldapservers.jobs; 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/ldapservers/src/main/java/org/apache/directory/studio/ldapservers/jobs/StartLdapServerWatchDogThread.java
plugins/ldapservers/src/main/java/org/apache/directory/studio/ldapservers/jobs/StartLdapServerWatchDogThread.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.ldapservers.jobs; import org.apache.directory.studio.ldapservers.model.LdapServer; import org.apache.directory.studio.ldapservers.model.LdapServerStatus; /** * This class implements a {@link Thread} that is used as a watch for the start of an LDAP Server. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class StartLdapServerWatchDogThread extends Thread { /** The server */ private LdapServer server; /** * Creates a new instance of StartLdapServerWatchDogThread. * * @param server * the LDAP Server */ private StartLdapServerWatchDogThread( LdapServer server ) { super(); this.server = server; } /** * {@inheritDoc} */ public void run() { // Getting the current time long startTime = System.currentTimeMillis(); // Calculating the watchdog time final long watchDog = startTime + ( 1000 * 60 * 1 ); // 3 minutes // Looping until the end of the watchdog time or when the server status is no longer 'starting' while ( ( System.currentTimeMillis() < watchDog ) && ( LdapServerStatus.STARTING == server.getStatus() ) ) { // We just wait one second before starting the test once // again try { Thread.sleep( 1000 ); } catch ( InterruptedException e1 ) { // Nothing to do... } } // We exited from the waiting loop // Checking if the watchdog time is expired if ( ( System.currentTimeMillis() >= watchDog ) && ( LdapServerStatus.STARTING == server.getStatus() ) ) { // TODO Display an error message... // Setting the status of the server to 'Stopped' server.setStatus( LdapServerStatus.STOPPED ); } } /** * Runs a new watchdog thread with the given LDAP Server. * * @param server * the LDAP Server */ public static void runNewWatchDogThread( LdapServer server ) { new StartLdapServerWatchDogThread( server ).start(); } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/ldapservers/src/main/java/org/apache/directory/studio/ldapservers/jobs/OpenConfigurationLdapServerRunnable.java
plugins/ldapservers/src/main/java/org/apache/directory/studio/ldapservers/jobs/OpenConfigurationLdapServerRunnable.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.ldapservers.jobs; import org.apache.directory.studio.common.core.jobs.StudioProgressMonitor; import org.apache.directory.studio.common.core.jobs.StudioRunnableWithProgress; import org.apache.directory.studio.ldapservers.model.LdapServer; import org.eclipse.core.runtime.jobs.Job; import org.eclipse.osgi.util.NLS; /** * This class implements a {@link Job} that is used to delete an LDAP Server. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class OpenConfigurationLdapServerRunnable implements StudioRunnableWithProgress { /** The server */ private LdapServer server; /** * Creates a new instance of StartLdapServerRunnable. * * @param server * the LDAP Server */ public OpenConfigurationLdapServerRunnable( LdapServer server ) { super(); this.server = server; } /** * {@inheritDoc} */ public String getErrorMessage() { return NLS .bind( Messages.getString( "OpenConfigurationLdapServerRunnable.UnableToOpenConfigurationForServer" ), new String[] //$NON-NLS-1$ { server.getName() } ); } /** * {@inheritDoc} */ public Object[] getLockedObjects() { return new Object[] { server }; } /** * {@inheritDoc} */ public String getName() { return NLS .bind( Messages.getString( "OpenConfigurationLdapServerRunnable.OpenConfigurationForServer" ), new String[] { server.getName() } ); //$NON-NLS-1$ } /** * {@inheritDoc} */ public void run( StudioProgressMonitor monitor ) { try { // Letting the LDAP Server Adapter open the configuration of the server server.getLdapServerAdapterExtension().getInstance().openConfiguration( server, monitor ); } catch ( Exception e ) { // Reporting the error to the monitor monitor.reportError( 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/ldapservers/src/main/java/org/apache/directory/studio/ldapservers/jobs/StartLdapServerRunnable.java
plugins/ldapservers/src/main/java/org/apache/directory/studio/ldapservers/jobs/StartLdapServerRunnable.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.ldapservers.jobs; import org.apache.directory.studio.common.core.jobs.StudioProgressMonitor; import org.apache.directory.studio.common.core.jobs.StudioRunnableWithProgress; import org.apache.directory.studio.ldapservers.model.LdapServer; import org.apache.directory.studio.ldapservers.model.LdapServerAdapter; import org.apache.directory.studio.ldapservers.model.LdapServerAdapterExtension; import org.apache.directory.studio.ldapservers.model.LdapServerStatus; import org.eclipse.core.runtime.jobs.Job; import org.eclipse.osgi.util.NLS; /** * This class implements a {@link Job} that is used to start an LDAP Server. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class StartLdapServerRunnable implements StudioRunnableWithProgress { /** The server */ private LdapServer server; /** * Creates a new instance of StartLdapServerRunnable. * * @param server * the LDAP Server */ public StartLdapServerRunnable( LdapServer server ) { super(); this.server = server; } /** * {@inheritDoc} */ public String getErrorMessage() { return NLS.bind( Messages.getString( "StartLdapServerRunnable.UnableToStartServer" ), new String[] //$NON-NLS-1$ { server.getName() } ); } /** * {@inheritDoc} */ public Object[] getLockedObjects() { return new Object[] { server }; } /** * {@inheritDoc} */ public String getName() { return NLS .bind( Messages.getString( "StartLdapServerRunnable.StartServer" ), new String[] { server.getName() } ); //$NON-NLS-1$ } /** * {@inheritDoc} */ public void run( StudioProgressMonitor monitor ) { // Setting the status on the server to 'starting' server.setStatus( LdapServerStatus.STARTING ); // Starting a new watchdog thread StartLdapServerWatchDogThread.runNewWatchDogThread( server ); // Launching the 'start()' method of the LDAP Server Adapter LdapServerAdapterExtension ldapServerAdapterExtension = server.getLdapServerAdapterExtension(); if ( ldapServerAdapterExtension != null ) { LdapServerAdapter ldapServerAdapter = ldapServerAdapterExtension.getInstance(); if ( ldapServerAdapter != null ) { try { ldapServerAdapter.start( server, monitor ); } catch ( Exception e ) { // Setting the server as stopped server.setStatus( LdapServerStatus.STOPPED ); // Reporting the error to the monitor monitor.reportError( 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/ldapservers/src/main/java/org/apache/directory/studio/ldapservers/jobs/StopLdapServerWatchDogThread.java
plugins/ldapservers/src/main/java/org/apache/directory/studio/ldapservers/jobs/StopLdapServerWatchDogThread.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.ldapservers.jobs; import org.apache.directory.studio.ldapservers.model.LdapServer; import org.apache.directory.studio.ldapservers.model.LdapServerStatus; /** * This class implements a {@link Thread} that is used as a watch for the stop of an LDAP Server. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class StopLdapServerWatchDogThread extends Thread { /** The server */ private LdapServer server; /** * Creates a new instance of StopLdapServerWatchDogThread. * * @param server * the LDAP Server */ private StopLdapServerWatchDogThread( LdapServer server ) { super(); this.server = server; } /** * {@inheritDoc} */ public void run() { // Getting the current time long startTime = System.currentTimeMillis(); // Calculating the watchdog time final long watchDog = startTime + ( 1000 * 60 * 1 ); // 3 minutes // Looping until the end of the watchdog time or when the server status is no longer 'starting' while ( ( System.currentTimeMillis() < watchDog ) && ( LdapServerStatus.STOPPING == server.getStatus() ) ) { // We just wait one second before starting the test once // again try { Thread.sleep( 1000 ); } catch ( InterruptedException e1 ) { // Nothing to do... } } // We exited from the waiting loop // Checking if the watchdog time is expired if ( ( System.currentTimeMillis() >= watchDog ) && ( LdapServerStatus.STOPPING == server.getStatus() ) ) { // TODO Display an error message... // Setting the status of the server to 'Started' server.setStatus( LdapServerStatus.STARTED ); } } /** * Runs a new watchdog thread with the given LDAP Server. * * @param server * the LDAP Server */ public static void runNewWatchDogThread( LdapServer server ) { new StopLdapServerWatchDogThread( server ).start(); } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/ldapservers/src/main/java/org/apache/directory/studio/ldapservers/model/LdapServerAdapterExtension.java
plugins/ldapservers/src/main/java/org/apache/directory/studio/ldapservers/model/LdapServerAdapterExtension.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.ldapservers.model; import org.apache.directory.studio.ldapservers.LdapServerAdapterExtensionsManager; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IConfigurationElement; import org.eclipse.jface.resource.ImageDescriptor; /** * The {@link LdapServerAdapterExtension} class represents an extension to the * LDAP Server Adapters extension point. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class LdapServerAdapterExtension { /** The extension point configuration */ private IConfigurationElement extensionPointConfiguration; /** The ID */ private String id; /** The name*/ private String name; /** The version */ private String version; /** The vendor */ private String vendor; /** The class name */ private String className; /** The {@link LdapServerAdapter} instance */ private LdapServerAdapter instance; /** The description */ private String description; /** The icon */ private ImageDescriptor icon; /** The configuration page class name */ private String configurationPageClassName; /** The flag to enable the open configuration action */ private boolean openConfigurationActionEnabled; /** * Gets the class name. * * @return * the class name */ public String getClassName() { return className; } /** * Gets the configuration page class name. * * @return * the configuration page class name */ public String getConfigurationPageClassName() { return configurationPageClassName; } /** * Gets the description. * * @return * the description */ public String getDescription() { return description; } /** * Gets the extension point configuration. * * @return * the extension point configuration */ public IConfigurationElement getExtensionPointConfiguration() { return extensionPointConfiguration; } /** * Gets the icon. * * @return * the icon */ public ImageDescriptor getIcon() { return icon; } /** * Gets the ID. * * @return * the ID */ public String getId() { return id; } /** * Gets the {@link LdapServerAdapter} instance. * * @return * the {@link LdapServerAdapter} instance */ public LdapServerAdapter getInstance() { return instance; } /** * Gets the name. * * @return * the name */ public String getName() { return name; } /** * Gets a new configuration page instance. * * @return * a new configuration page instance */ public LdapServerAdapterConfigurationPage getNewConfigurationPageInstance() { try { return ( LdapServerAdapterConfigurationPage ) extensionPointConfiguration .createExecutableExtension( LdapServerAdapterExtensionsManager.CONFIGURATION_PAGE_ATTR ); } catch ( CoreException e ) { return null; } } /** * Gets the vendor. * * @return * the vendor */ public String getVendor() { return vendor; } /** * Gets the version. * * @return * the version */ public String getVersion() { return version; } /** * Returns the flag to enable the open configuration action. * * @return the flag to enable the open configuration action */ public boolean isOpenConfigurationActionEnabled() { return openConfigurationActionEnabled; } /** * Sets the class name. * * @param className * the class name */ public void setClassName( String className ) { this.className = className; } /** * Sets the configuration page class name. * * @param configurationPageClassName * the configuration page class name */ public void setConfigurationPageClassName( String configurationPageClassName ) { this.configurationPageClassName = configurationPageClassName; } /** * Sets the description. * * @param description * the description */ public void setDescription( String description ) { this.description = description; } /** * Sets the extension point configuration. * * @param IConfigurationElement * the extension point configuration */ public void setExtensionPointConfiguration( IConfigurationElement extensionPointConfiguration ) { this.extensionPointConfiguration = extensionPointConfiguration; } /** * Sets the icon. * * @param icon * the icon */ public void setIcon( ImageDescriptor icon ) { this.icon = icon; } /** * Sets the ID. * * @param id * the ID */ public void setId( String id ) { this.id = id; } /** * Sets the {@link LdapServerAdapter} instance. * * @param instance * the {@link LdapServerAdapter} instance */ public void setInstance( LdapServerAdapter instance ) { this.instance = instance; } /** * Sets the name. * * @param name * the name */ public void setName( String name ) { this.name = name; } /** * Sets the flag to enable the open configuration action. * * @param openConfigurationActionEnabled the flag to enable the open configuration action */ public void setOpenConfigurationActionEnabled( boolean openConfigurationActionEnabled ) { this.openConfigurationActionEnabled = openConfigurationActionEnabled; } /** * Sets the vendor. * * @param vendor * the vendor */ public void setVendor( String vendor ) { this.vendor = vendor; } /** * Sets the version. * * @param version * the version */ public void setVersion( String version ) { this.version = version; } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/ldapservers/src/main/java/org/apache/directory/studio/ldapservers/model/LdapServerAdapterConfigurationPage.java
plugins/ldapservers/src/main/java/org/apache/directory/studio/ldapservers/model/LdapServerAdapterConfigurationPage.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.ldapservers.model; import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; /** * This interface defines a configuration page for an {@link LdapServerAdapter}. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public interface LdapServerAdapterConfigurationPage { /** * Creates the control for the configuration page. * * @param parent the parent control * @return the created control */ Control createControl( Composite parent ); /** * Gets the description. * * @return the description */ String getDescription(); /** * Gets the error message. * * @return the error message */ String getErrorMessage(); /** * Gets the ID. * * @return the ID */ String getId(); /** * Gets the {@link ImageDescriptor}. * * @return the {@link ImageDescriptor} */ ImageDescriptor getImageDescriptor(); /** * Gets the title. * * @return the title */ String getTitle(); /** * Indicates if the page is complete. * * @return <code>true</code> if the page is complete, * <code>false</code> if not. */ boolean isPageComplete(); /** * Loads configuration information from the given LDAP server. * * @param ldapServer the LDAP server */ void loadConfiguration( LdapServer ldapServer ); /** * Saves the configuration information to the given LDAP server. * * @param ldapServer the LDAP server */ void saveConfiguration( LdapServer ldapServer ); /** * Sets a modify listener. * * @param modifyListener the modify listener */ void setModifyListener( LdapServerAdapterConfigurationPageModifyListener modifyListener ); /** * Validates the configuration page */ void validate(); }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/ldapservers/src/main/java/org/apache/directory/studio/ldapservers/model/UnknownLdapServerAdapterExtension.java
plugins/ldapservers/src/main/java/org/apache/directory/studio/ldapservers/model/UnknownLdapServerAdapterExtension.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.ldapservers.model; import org.apache.directory.studio.common.core.jobs.StudioProgressMonitor; import org.apache.directory.studio.common.ui.CommonUIUtils; import org.eclipse.osgi.util.NLS; import org.eclipse.swt.widgets.Display; /** * The {@link UnknownLdapServerAdapterExtension} class represents an extension to the * LDAP Server Adapters extension point that can not be found while parsing the server instances file. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class UnknownLdapServerAdapterExtension extends LdapServerAdapterExtension { /** * Creates a new instance of UnknownLdapServerAdapterExtension. */ public UnknownLdapServerAdapterExtension() { // Setting behavior for this particular LDAP Server Adapter Extension setInstance( new LdapServerAdapter() { /** * {@inheritDoc} */ public void add( LdapServer server, StudioProgressMonitor monitor ) throws Exception { showWarningDialog(); } /** * {@inheritDoc} */ public void delete( LdapServer server, StudioProgressMonitor monitor ) throws Exception { // Nothing to do } /** * {@inheritDoc} */ public void openConfiguration( LdapServer server, StudioProgressMonitor monitor ) throws Exception { showWarningDialog(); } /** * {@inheritDoc} */ public void start( LdapServer server, StudioProgressMonitor monitor ) throws Exception { showWarningDialog(); server.setStatus( LdapServerStatus.STOPPED ); } /** * {@inheritDoc} */ public void stop( LdapServer server, StudioProgressMonitor monitor ) throws Exception { showWarningDialog(); server.setStatus( LdapServerStatus.STOPPED ); } /** * Shows the warning dialog. */ private void showWarningDialog() { Display.getDefault().asyncExec( new Runnable() { public void run() { CommonUIUtils.openWarningDialog( Messages.getString( "UnknownLdapServerAdapterExtension.ServerAdapterNotAvailable" ), //$NON-NLS-1$ NLS.bind( Messages .getString( "UnknownLdapServerAdapterExtension.ServerCreatedWithServerAdapterNoLongerAvailable" ), //$NON-NLS-1$ new String[] { getId(), getName(), getVendor(), getVersion() } ) ); } } ); } /** * {@inheritDoc} */ public String[] checkPortsBeforeServerStart( LdapServer server ) { return 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/ldapservers/src/main/java/org/apache/directory/studio/ldapservers/model/LdapServerAdapterConfigurationPageModifyListener.java
plugins/ldapservers/src/main/java/org/apache/directory/studio/ldapservers/model/LdapServerAdapterConfigurationPageModifyListener.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.ldapservers.model; /** * A {@link LdapServerAdapterConfigurationPageModifyListener} listens for modifications of the * {@link LdapServerAdapterConfigurationPage}. */ public interface LdapServerAdapterConfigurationPageModifyListener { /** * Indicates that the configuration page was modified. */ void configurationPageModified(); }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/ldapservers/src/main/java/org/apache/directory/studio/ldapservers/model/LdapServerAdapter.java
plugins/ldapservers/src/main/java/org/apache/directory/studio/ldapservers/model/LdapServerAdapter.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.ldapservers.model; import org.apache.directory.studio.common.core.jobs.StudioProgressMonitor; /** * The {@link LdapServerAdapter} interface defines the required methods * to implement an LDAP Server adapter. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public interface LdapServerAdapter { /** * This method is called when a server is added. * * @param server * the server * @param monitor * the progress monitor * @throws Exception * if an error occurs when adding the server */ void add( LdapServer server, StudioProgressMonitor monitor ) throws Exception; /** * This method is called when a server is deleted. * * @param server * the server * @param monitor * the progress monitor * @throws Exception * if an error occurs when deleting the server */ void delete( LdapServer server, StudioProgressMonitor monitor ) throws Exception; /** * This method is called when a server is double-clicked in the 'LDAP Servers' view. * * @param server * the server * @param monitor * the progress monitor * @throws Exception * if an error occurs when opening the configuration of the server */ void openConfiguration( LdapServer server, StudioProgressMonitor monitor ) throws Exception; /** * This method is called when a server needs to be started. * * @param server * the server * @param monitor * the progress monitor * @throws Exception * if an error occurs when starting the server */ void start( LdapServer server, StudioProgressMonitor monitor ) throws Exception; /** * This method is called when a server needs to be stopped. * * @param server * the server * @param monitor * the progress monitor * @throws Exception * if an error occurs when stopping the server */ void stop( LdapServer server, StudioProgressMonitor monitor ) throws Exception; /** * Checks the ports before the server starts. * <p> * The return strings must have the following format: {PROTOCOL} ({PORT}) * * @param server the server * @return an array of error message, one for each port being already used. * @throws Exception * if an error occurs when checking the ports before the server starts */ String[] checkPortsBeforeServerStart( LdapServer server ) throws Exception; }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/ldapservers/src/main/java/org/apache/directory/studio/ldapservers/model/LdapServerActionFilterAdapter.java
plugins/ldapservers/src/main/java/org/apache/directory/studio/ldapservers/model/LdapServerActionFilterAdapter.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.ldapservers.model; import org.apache.directory.studio.ldapservers.actions.CreateConnectionActionHelper; import org.eclipse.ui.IActionFilter; /** * This class implements an {@link IActionFilter} adapter for the {@link LdapServer} class. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class LdapServerActionFilterAdapter implements IActionFilter { // Identifier and value strings private static final String ID = "id"; //$NON-NLS-1$ private static final String NAME = "name"; //$NON-NLS-1$ private static final Object STATUS = "status"; //$NON-NLS-1$ private static final Object STATUS_STARTED = "started"; //$NON-NLS-1$ private static final Object STATUS_STARTING = "starting"; //$NON-NLS-1$ private static final Object STATUS_STOPPED = "stopped"; //$NON-NLS-1$ private static final Object STATUS_STOPPING = "stopping"; //$NON-NLS-1$ private static final Object STATUS_UNKNOWN = "unknown"; //$NON-NLS-1$ private static final Object EXTENSION_ID = "extensionId"; //$NON-NLS-1$ private static final Object EXTENSION_NAME = "extensionName"; //$NON-NLS-1$ private static final Object EXTENSION_VERSION = "extensionVersion"; //$NON-NLS-1$ private static final Object EXTENSION_VENDOR = "extensionVendor"; //$NON-NLS-1$ private static final Object HAS_CONFIGURATION_PAGE = "hasConfigurationPage"; //$NON-NLS-1$ private static final Object IS_LDAP_PERSPECTIVE_AVAILABLE = "isLdapPerspectiveAvailable"; //$NON-NLS-1$ /** The class instance */ private static LdapServerActionFilterAdapter INSTANCE = new LdapServerActionFilterAdapter(); /** * Private constructor. */ private LdapServerActionFilterAdapter() { // Nothing to initialize } /** * Returns an instance of {@link LdapServerActionFilterAdapter}. * * @return * an instance of {@link LdapServerActionFilterAdapter} */ public static LdapServerActionFilterAdapter getInstance() { return INSTANCE; } /** * {@inheritDoc} */ public boolean testAttribute( Object target, String name, String value ) { if ( target instanceof LdapServer ) { LdapServer server = ( LdapServer ) target; // ID if ( ID.equals( name ) ) { return value.equals( server.getId() ); } // NAME else if ( NAME.equals( name ) ) { return value.equals( server.getName() ); } // STATUS else if ( STATUS.equals( name ) ) { switch ( server.getStatus() ) { case STARTED: return value.equals( STATUS_STARTED ); case STARTING: return value.equals( STATUS_STARTING ); case STOPPED: return value.equals( STATUS_STOPPED ); case STOPPING: return value.equals( STATUS_STOPPING ); case UNKNOWN: return value.equals( STATUS_UNKNOWN ); } } // EXTENSION ID else if ( EXTENSION_ID.equals( name ) ) { if ( server.getLdapServerAdapterExtension() != null ) { return value.equals( server.getLdapServerAdapterExtension().getId() ); } } // EXTENSION NAME else if ( EXTENSION_NAME.equals( name ) ) { if ( server.getLdapServerAdapterExtension() != null ) { return value.equals( server.getLdapServerAdapterExtension().getName() ); } } // EXTENSION VERSION else if ( EXTENSION_VERSION.equals( name ) ) { if ( server.getLdapServerAdapterExtension() != null ) { return value.equals( server.getLdapServerAdapterExtension().getVersion() ); } } // EXTENSION VENDOR else if ( EXTENSION_VENDOR.equals( name ) ) { if ( server.getLdapServerAdapterExtension() != null ) { return value.equals( server.getLdapServerAdapterExtension().getVendor() ); } } // HAS CONFIGURATION PAGE else if ( HAS_CONFIGURATION_PAGE.equals( name ) ) { String configurationPageClassName = server.getLdapServerAdapterExtension() .getConfigurationPageClassName(); boolean hasConfigurationPage = ( ( configurationPageClassName != null ) && ( !"" //$NON-NLS-1$ .equals( configurationPageClassName ) ) ); return value.equalsIgnoreCase( hasConfigurationPage ? "true" : "false" ); //$NON-NLS-1$ //$NON-NLS-2$ } // IS LDAP PERSPECTIVE AVAILABLE else if ( IS_LDAP_PERSPECTIVE_AVAILABLE.equals( name ) ) { boolean isLdapPerspectiveAvailable = CreateConnectionActionHelper.isLdapBrowserPluginsAvailable(); boolean booleanValue = Boolean.parseBoolean( value ); return isLdapPerspectiveAvailable == booleanValue; } } 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/ldapservers/src/main/java/org/apache/directory/studio/ldapservers/model/LdapServerListener.java
plugins/ldapservers/src/main/java/org/apache/directory/studio/ldapservers/model/LdapServerListener.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.ldapservers.model; /** * This interface defines a listener on an LDAP Server instance. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public interface LdapServerListener { /** * This method is called when the server is changed. * * @param event the server event */ void serverChanged( LdapServerEvent event ); }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/ldapservers/src/main/java/org/apache/directory/studio/ldapservers/model/Messages.java
plugins/ldapservers/src/main/java/org/apache/directory/studio/ldapservers/model/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.ldapservers.model; import java.util.MissingResourceException; import java.util.ResourceBundle; import org.eclipse.osgi.util.NLS; /** * This class get messages from the resources file. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class Messages extends NLS { /** 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/ldapservers/src/main/java/org/apache/directory/studio/ldapservers/model/LdapServer.java
plugins/ldapservers/src/main/java/org/apache/directory/studio/ldapservers/model/LdapServer.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.ldapservers.model; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.UUID; import org.eclipse.core.runtime.IAdaptable; import org.eclipse.ui.IActionFilter; /** * The {@link LdapServer} interface defines the required methods * to implement an LDAP Server instance. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class LdapServer implements IAdaptable { /** The ID of the server */ private String id; /** The name of the server*/ private String name; /** The status of the server */ private LdapServerStatus status = LdapServerStatus.STOPPED; /** The LDAP Server Adapter Extension */ private LdapServerAdapterExtension ldapServerAdapterExtension; /** The list of listeners */ private List<LdapServerListener> listeners = new ArrayList<LdapServerListener>(); /** The Map for custom objects */ private Map<String, Object> customObjectsMap = new HashMap<String, Object>(); /** The Map for configuration parameters */ private Map<String, Object> configurationParameters = new HashMap<String, Object>(); /** * Creates a new instance of LDAP Server. * <p> * An ID is automatically created. */ public LdapServer() { id = createId(); } /** * Creates a new instance of LDAP Server. * <p> * An ID is automatically created. * * @param name * the name of the server */ public LdapServer( String name ) { this.name = name; id = createId(); } /** * Creates a new ID. * * @return * a new ID */ private static String createId() { return UUID.randomUUID().toString(); } /** * Adds the {@link LdapServerListener} to the server. * * @param listener * the listener to be added */ public void addListener( LdapServerListener listener ) { if ( !listeners.contains( listener ) ) { listeners.add( listener ); } } /** * Returns the value to which the specified key is mapped, * or null if no mapping for the key is found. * * @param key * the key * @return * the value to which the specified key is mapped, * or null if no mapping for the key is found. */ public Object getCustomObject( String key ) { return customObjectsMap.get( key ); } /** * Returns the value to which the specified key is mapped, * or null if no mapping for the key is found. * * @param key * the key * @return * the value to which the specified key is mapped, * or null if no mapping for the key is found. */ public Object getConfigurationParameter( String key ) { return configurationParameters.get( key ); } /** * Gets the configuration parameters. * * @return the configuration parameters */ public Map<String, Object> getConfigurationParameters() { return configurationParameters; } /** * Gets the id of the server. * * @return * the id of the server */ public String getId() { return id; } /** * Gets the associated {@link LdapServerAdapterExtension}. * * @return * the associated {@link LdapServerAdapterExtension} */ public LdapServerAdapterExtension getLdapServerAdapterExtension() { return ldapServerAdapterExtension; } /** * Gets the name of the server. * * @return * the name of the server */ public String getName() { return name; } /** * Gets the status of the server. * * @return * the status of the server */ public LdapServerStatus getStatus() { return status; } /** * Associates the specified value with the specified key. * * @param key * the key * @param value * the value */ public void putCustomObject( String key, Object value ) { customObjectsMap.put( key, value ); } /** * Associates the specified value with the specified key. * * @param key * the key * @param value * the value */ public void putConfigurationParameter( String key, Object value ) { configurationParameters.put( key, value ); } /** * Removes the value to which the specified key is mapped. * <p> * Returns the value previously associated the key, * or null if there was no mapping for the key. * * @param key * @return */ public Object removeCustomObject( String key ) { return customObjectsMap.remove( key ); } /** * Removes the value to which the specified key is mapped. * <p> * Returns the value previously associated the key, * or null if there was no mapping for the key. * * @param key * @return */ public Object removeConfigurationParameter( String key ) { return configurationParameters.remove( key ); } /** * Removes the {@link LdapServerListener} from the server. * * @param listener * the listener to be removed */ public void removeListener( LdapServerListener listener ) { if ( !listeners.contains( listener ) ) { listeners.remove( listener ); } } /** * Sets the ID of the server * * @param id * the ID of the server */ public void setId( String id ) { this.id = id; } public void setLdapServerAdapterExtension( LdapServerAdapterExtension ldapServerAdapterExtension ) { this.ldapServerAdapterExtension = ldapServerAdapterExtension; } /** * Sets the name of the server * * @param name * the name of the server */ public void setName( String name ) { if ( this.name == name ) { return; } this.name = name; fireServerNameChangeEvent(); } /** * Fire a server listener name change event. */ private void fireServerNameChangeEvent() { for ( LdapServerListener listener : listeners.toArray( new LdapServerListener[0] ) ) { listener.serverChanged( new LdapServerEvent( this, LdapServerEventType.RENAMED ) ); } } /** * Sets the status * * @param status * the status */ public void setStatus( LdapServerStatus status ) { if ( this.status == status ) { return; } this.status = status; fireServerStateChangeEvent(); } /** * Fires a server listener status change event. */ private void fireServerStateChangeEvent() { for ( LdapServerListener listener : listeners.toArray( new LdapServerListener[0] ) ) { listener.serverChanged( new LdapServerEvent( this, LdapServerEventType.STATUS_CHANGED ) ); } } /** * {@inheritDoc} */ public Object getAdapter( Class adapter ) { if ( adapter.isAssignableFrom( IActionFilter.class ) ) { return LdapServerActionFilterAdapter.getInstance(); } 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/ldapservers/src/main/java/org/apache/directory/studio/ldapservers/model/AbstractLdapServerAdapterConfigurationPage.java
plugins/ldapservers/src/main/java/org/apache/directory/studio/ldapservers/model/AbstractLdapServerAdapterConfigurationPage.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.ldapservers.model; import org.eclipse.jface.resource.ImageDescriptor; /** * This interface defines a configuration page for an {@link LdapServerAdapter}. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public abstract class AbstractLdapServerAdapterConfigurationPage implements LdapServerAdapterConfigurationPage { /** The id */ protected String id; /** The title */ protected String title; /** The description */ protected String description; /** The image descriptor */ protected ImageDescriptor imageDescriptor; /** The error message */ protected String errorMessage; /** The flag for page completion */ protected boolean pageComplete = true; /** The modify listener */ protected LdapServerAdapterConfigurationPageModifyListener modifyListener; /** * {@inheritDoc} */ public String getDescription() { return description; } /** * {@inheritDoc} */ public String getErrorMessage() { return errorMessage; } /** * {@inheritDoc} */ public String getId() { return id; } /** * {@inheritDoc} */ public ImageDescriptor getImageDescriptor() { return imageDescriptor; } /** * {@inheritDoc} */ public String getTitle() { return title; } /** * {@inheritDoc} */ public boolean isPageComplete() { return pageComplete; } /** * Sets the description. * * @param description the description to set */ public void setDescription( String description ) { this.description = description; } /** * Sets the error message. * * @param errorMessage the errorMessage to set */ public void setErrorMessage( String errorMessage ) { this.errorMessage = errorMessage; setPageComplete( errorMessage == null ); } /** * Sets the id. * * @param id the id to set */ public void setId( String id ) { this.id = id; } /** * Sets the {@link ImageDescriptor}. * * @param imageDescriptor the imageDescriptor to set */ public void setImageDescriptor( ImageDescriptor imageDescriptor ) { this.imageDescriptor = imageDescriptor; } /** * {@inheritDoc} */ public void setModifyListener( LdapServerAdapterConfigurationPageModifyListener modifyListener ) { this.modifyListener = modifyListener; } /** * Sets the page completion flag. * * @param pageComplete the pageComplete to set */ public void setPageComplete( boolean pageComplete ) { this.pageComplete = pageComplete; } /** * Sets the title. * * @param title the title to set */ public void setTitle( String title ) { this.title = title; } /** * Called when an input field is modified. */ protected final void configurationPageModified() { validate(); fireConfigurationPageModified(); } /** * Fires a configuration page modified event when the page was modified. */ protected void fireConfigurationPageModified() { if ( modifyListener != null ) { modifyListener.configurationPageModified(); } } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/ldapservers/src/main/java/org/apache/directory/studio/ldapservers/model/LdapServerStatus.java
plugins/ldapservers/src/main/java/org/apache/directory/studio/ldapservers/model/LdapServerStatus.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.ldapservers.model; /** * This enum defines the various statuses of an LDAP Server. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public enum LdapServerStatus { STARTED, STARTING, STOPPED, STOPPING, UNKNOWN, REPAIRING }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/ldapservers/src/main/java/org/apache/directory/studio/ldapservers/model/LdapServerEventType.java
plugins/ldapservers/src/main/java/org/apache/directory/studio/ldapservers/model/LdapServerEventType.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.ldapservers.model; /** * This enums defines the different server events notifications. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public enum LdapServerEventType { RENAMED, STATUS_CHANGED }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/ldapservers/src/main/java/org/apache/directory/studio/ldapservers/model/LdapServerEvent.java
plugins/ldapservers/src/main/java/org/apache/directory/studio/ldapservers/model/LdapServerEvent.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.ldapservers.model; /** * This class defines a server event. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class LdapServerEvent { /** The server */ private LdapServer server; /** The kind of event */ private LdapServerEventType kind; /** * Creates a new instance of LdapServerEvent. * * @param server * the server * @param kind * the kind of event */ public LdapServerEvent( LdapServer server, LdapServerEventType kind ) { super(); this.server = server; this.kind = kind; } /** * Gets the server. * * @return * the server */ public LdapServer getServer() { return server; } /** * Sets the server. * * @param server * the server */ public void setServer( LdapServer server ) { this.server = server; } /** * Gets the kind of event. * * @return * the kind of event */ public LdapServerEventType getKind() { return kind; } /** * Sets the kind of event. * * @param kind * the kind of event */ public void setKind( LdapServerEventType kind ) { this.kind = kind; } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/ldapservers/src/main/java/org/apache/directory/studio/ldapservers/actions/DeleteAction.java
plugins/ldapservers/src/main/java/org/apache/directory/studio/ldapservers/actions/DeleteAction.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.ldapservers.actions; import org.apache.directory.studio.ldapservers.LdapServersPluginConstants; import org.apache.directory.studio.ldapservers.dialogs.DeleteServerDialog; import org.apache.directory.studio.ldapservers.jobs.DeleteLdapServerRunnable; import org.apache.directory.studio.ldapservers.jobs.StudioLdapServerJob; import org.apache.directory.studio.ldapservers.model.LdapServer; import org.apache.directory.studio.ldapservers.views.ServersView; import org.eclipse.jface.action.Action; import org.eclipse.jface.action.IAction; import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.StructuredSelection; import org.eclipse.ui.ISharedImages; import org.eclipse.ui.IWorkbenchWindow; import org.eclipse.ui.IWorkbenchWindowActionDelegate; import org.eclipse.ui.PlatformUI; /** * This class implements the delete action for a server. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class DeleteAction extends Action implements IWorkbenchWindowActionDelegate { /** The associated view */ private ServersView view; /** * Creates a new instance of DeleteAction. */ public DeleteAction() { super( Messages.getString( "DeleteAction.Delete" ) ); //$NON-NLS-1$ init(); } /** * Creates a new instance of DeleteAction. * * @param view * the associated view */ public DeleteAction( ServersView view ) { super( Messages.getString( "DeleteAction.Delete" ) ); //$NON-NLS-1$ this.view = view; init(); } /** * Initializes the action. */ private void init() { setId( LdapServersPluginConstants.CMD_DELETE ); setActionDefinitionId( LdapServersPluginConstants.CMD_DELETE ); setToolTipText( Messages.getString( "DeleteAction.DeleteToolTip" ) ); //$NON-NLS-1$ setImageDescriptor( PlatformUI.getWorkbench().getSharedImages() .getImageDescriptor( ISharedImages.IMG_TOOL_DELETE ) ); } /** * {@inheritDoc} */ public void run() { if ( view != null ) { // What we get from the TableViewer is a StructuredSelection StructuredSelection selection = ( StructuredSelection ) view.getViewer().getSelection(); // Here's the real object LdapServer server = ( LdapServer ) selection.getFirstElement(); // Asking for confirmation DeleteServerDialog dsd = new DeleteServerDialog( view.getSite().getShell(), server ); if ( dsd.open() == DeleteServerDialog.OK ) { // Creating and scheduling the job to delete the server StudioLdapServerJob job = new StudioLdapServerJob( new DeleteLdapServerRunnable( server ) ); job.schedule(); } } } /** * {@inheritDoc} */ public void run( IAction action ) { run(); } /** * {@inheritDoc} */ public void dispose() { // Nothing to do } /** * {@inheritDoc} */ public void init( IWorkbenchWindow window ) { // Nothing to do } /** * {@inheritDoc} */ public void selectionChanged( IAction action, ISelection 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/ldapservers/src/main/java/org/apache/directory/studio/ldapservers/actions/CreateConnectionActionHelper.java
plugins/ldapservers/src/main/java/org/apache/directory/studio/ldapservers/actions/CreateConnectionActionHelper.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.ldapservers.actions; import org.apache.directory.studio.connection.core.Connection; import org.apache.directory.studio.connection.core.ConnectionCorePlugin; import org.apache.directory.studio.ldapservers.model.LdapServer; import org.eclipse.core.runtime.Platform; import org.eclipse.jface.dialogs.IDialogConstants; import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.osgi.util.NLS; import org.eclipse.ui.IPerspectiveDescriptor; import org.eclipse.ui.IWorkbenchWindow; import org.eclipse.ui.PlatformUI; import org.osgi.framework.Bundle; /** * This class implements a helper class of the create connection action for a server. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class CreateConnectionActionHelper { public static void createLdapBrowserConnection( LdapServer server, Connection connection ) { // Adding the connection to the connection manager ConnectionCorePlugin.getDefault().getConnectionManager().addConnection( connection ); // Adding the connection to the root connection folder ConnectionCorePlugin.getDefault().getConnectionFolderManager().getRootConnectionFolder() .addConnectionId( connection.getId() ); // Getting the window, LDAP perspective and current perspective IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); IPerspectiveDescriptor ldapPerspective = getLdapPerspective(); IPerspectiveDescriptor currentPerspective = window.getActivePage().getPerspective(); // Checking if we are already in the LDAP perspective if ( ( ldapPerspective != null ) && ( ldapPerspective.equals( currentPerspective ) ) ) { // As we're already in the LDAP perspective, we only indicate to the user // the name of the connection that has been created MessageDialog dialog = new MessageDialog( window.getShell(), Messages.getString( "CreateConnectionActionHelper.ConnectionCreated" ), null, //$NON-NLS-1$ NLS.bind( Messages.getString( "CreateConnectionActionHelper.ConnectionCalledCreated" ), new String[] { connection.getName() } ), MessageDialog.INFORMATION, //$NON-NLS-1$ new String[] { IDialogConstants.OK_LABEL }, MessageDialog.OK ); dialog.open(); } else { // We're not already in the LDAP perspective, we indicate to the user // the name of the connection that has been created and we ask him // if we wants to switch to the LDAP perspective MessageDialog dialog = new MessageDialog( window.getShell(), Messages.getString( "CreateConnectionActionHelper.ConnectionCreated" ), null, //$NON-NLS-1$ NLS.bind( Messages.getString( "CreateConnectionActionHelper.ConnectionCalledCreatedSwitch" ), new String[] { connection.getName() } ), //$NON-NLS-1$ MessageDialog.INFORMATION, new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL }, MessageDialog.OK ); if ( dialog.open() == MessageDialog.OK ) { // Switching to the LDAP perspective window.getActivePage().setPerspective( ldapPerspective ); } } } /** * Get the LDAP perspective. * * @return * the LDAP perspective */ private static IPerspectiveDescriptor getLdapPerspective() { for ( IPerspectiveDescriptor perspective : PlatformUI.getWorkbench().getPerspectiveRegistry().getPerspectives() ) { if ( "org.apache.directory.studio.ldapbrowser.ui.perspective.BrowserPerspective" //$NON-NLS-1$ .equalsIgnoreCase( perspective.getId() ) ) { return perspective; } } return null; } /** * Indicates if the LDAP Browser plugins are available or not. * * @return * <code>true</code> if the LDAP Browser plugins are available, * <code>false</code> if not. */ public static boolean isLdapBrowserPluginsAvailable() { String[] bundleNames = new String[] { "org.apache.directory.studio.connection.core", // Connection Core Plugin "org.apache.directory.studio.connection.ui", // Connection UI Plugin "org.apache.directory.studio.ldapbrowser.common", // LDAP Browser Common Plugin "org.apache.directory.studio.ldapbrowser.core", // LDAP Browser Core Plugin "org.apache.directory.studio.ldapbrowser.ui", // LDAP Browser UI Plugin "org.apache.directory.studio.ldifeditor", // LDIF Editor Plugin "org.apache.directory.studio.ldifparser" // LDIF Parser Plugin }; for ( String bundleName : bundleNames ) { Bundle bundle = Platform.getBundle( bundleName ); if ( ( bundle == null ) || ( bundle.getState() == Bundle.UNINSTALLED ) ) { return false; } } 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/ldapservers/src/main/java/org/apache/directory/studio/ldapservers/actions/NewServerAction.java
plugins/ldapservers/src/main/java/org/apache/directory/studio/ldapservers/actions/NewServerAction.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.ldapservers.actions; import org.apache.directory.studio.ldapservers.LdapServersPlugin; import org.apache.directory.studio.ldapservers.LdapServersPluginConstants; import org.apache.directory.studio.ldapservers.wizards.NewServerWizard; import org.eclipse.jface.action.Action; import org.eclipse.jface.action.IAction; import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.StructuredSelection; import org.eclipse.jface.wizard.WizardDialog; import org.eclipse.ui.IWorkbenchWindow; import org.eclipse.ui.IWorkbenchWindowActionDelegate; import org.eclipse.ui.PlatformUI; /** * This class implements the new server action. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class NewServerAction extends Action implements IWorkbenchWindowActionDelegate { /** * Creates a new instance of NewServerAction. */ public NewServerAction() { super( Messages.getString( "NewServerAction.NewServer" ) ); //$NON-NLS-1$ setId( LdapServersPluginConstants.CMD_NEW_SERVER ); setActionDefinitionId( LdapServersPluginConstants.CMD_NEW_SERVER ); setToolTipText( Messages.getString( "NewServerAction.NewServerToolTip" ) ); //$NON-NLS-1$ setImageDescriptor( LdapServersPlugin.getDefault().getImageDescriptor( LdapServersPluginConstants.IMG_SERVER_NEW ) ); } /** * {@inheritDoc} */ public void run() { // Instantiates and initializes the wizard NewServerWizard wizard = new NewServerWizard(); wizard.init( PlatformUI.getWorkbench(), StructuredSelection.EMPTY ); // Instantiates the wizard container with the wizard and opens it WizardDialog dialog = new WizardDialog( PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), wizard ); dialog.create(); dialog.open(); } /** * {@inheritDoc} */ public void run( IAction action ) { run(); } /** * {@inheritDoc} */ public void dispose() { // Nothing to do } /** * {@inheritDoc} */ public void init( IWorkbenchWindow window ) { // Nothing to do } /** * {@inheritDoc} */ public void selectionChanged( IAction action, ISelection 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/ldapservers/src/main/java/org/apache/directory/studio/ldapservers/actions/RenameAction.java
plugins/ldapservers/src/main/java/org/apache/directory/studio/ldapservers/actions/RenameAction.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.ldapservers.actions; import org.apache.directory.studio.ldapservers.LdapServersManager; import org.apache.directory.studio.ldapservers.LdapServersPluginConstants; import org.apache.directory.studio.ldapservers.model.LdapServer; import org.apache.directory.studio.ldapservers.views.ServersView; import org.eclipse.jface.action.Action; import org.eclipse.jface.action.IAction; import org.eclipse.jface.dialogs.IInputValidator; import org.eclipse.jface.dialogs.InputDialog; import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.StructuredSelection; import org.eclipse.ui.IWorkbenchWindow; import org.eclipse.ui.IWorkbenchWindowActionDelegate; /** * This class implements the open action for a server. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class RenameAction extends Action implements IWorkbenchWindowActionDelegate { /** The associated view */ private ServersView view; /** * Creates a new instance of RenameAction. * * @param view * the associated view */ public RenameAction( ServersView view ) { this.view = view; setText( Messages.getString( "RenameAction.Rename" ) ); //$NON-NLS-1$ setToolTipText( Messages.getString( "RenameAction.RenameToolTip" ) ); //$NON-NLS-1$ setId( LdapServersPluginConstants.CMD_RENAME ); setActionDefinitionId( LdapServersPluginConstants.CMD_RENAME ); } /** * {@inheritDoc} */ public void run() { if ( view != null ) { // Getting the selected server StructuredSelection selection = ( StructuredSelection ) view.getViewer().getSelection(); final LdapServer server = ( LdapServer ) selection.getFirstElement(); if ( server != null ) { IInputValidator validator = new IInputValidator() { public String isValid( String newName ) { if ( server.getName().equals( newName ) ) { return null; } else if ( !LdapServersManager.getDefault().isNameAvailable( newName ) ) { return Messages.getString( "RenameAction.ErrorNameInUse" ); //$NON-NLS-1$ } else { return null; } } }; // Opening a dialog to ask the user a new name for the server InputDialog dialog = new InputDialog( view.getSite().getShell(), Messages.getString( "RenameAction.RenameServer" ), //$NON-NLS-1$ Messages.getString( "RenameAction.NewName" ), //$NON-NLS-1$ server.getName(), validator ); dialog.open(); String newName = dialog.getValue(); if ( newName != null ) { server.setName( newName ); } } } } /** * {@inheritDoc} */ public void run( IAction action ) { run(); } /** * {@inheritDoc} */ public void dispose() { // Nothing to do } /** * {@inheritDoc} */ public void init( IWorkbenchWindow window ) { // Nothing to do } /** * {@inheritDoc} */ public void selectionChanged( IAction action, ISelection 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/ldapservers/src/main/java/org/apache/directory/studio/ldapservers/actions/StopAction.java
plugins/ldapservers/src/main/java/org/apache/directory/studio/ldapservers/actions/StopAction.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.ldapservers.actions; import org.apache.directory.studio.ldapservers.LdapServersPlugin; import org.apache.directory.studio.ldapservers.LdapServersPluginConstants; import org.apache.directory.studio.ldapservers.jobs.StopLdapServerRunnable; import org.apache.directory.studio.ldapservers.jobs.StudioLdapServerJob; import org.apache.directory.studio.ldapservers.model.LdapServer; import org.apache.directory.studio.ldapservers.views.ServersView; import org.eclipse.jface.action.Action; import org.eclipse.jface.action.IAction; import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.StructuredSelection; import org.eclipse.ui.IWorkbenchWindow; import org.eclipse.ui.IWorkbenchWindowActionDelegate; /** * This class implements the stop action for a server. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class StopAction extends Action implements IWorkbenchWindowActionDelegate { /** The associated view */ private ServersView view; /** * Creates a new instance of StopAction. */ public StopAction() { super( Messages.getString( "StopAction.Stop" ) ); //$NON-NLS-1$ init(); } /** * Creates a new instance of StopAction. * * @param view * the associated view */ public StopAction( ServersView view ) { super( Messages.getString( "StopAction.Stop" ) ); //$NON-NLS-1$ this.view = view; init(); } /** * Initializes the action. */ private void init() { setId( LdapServersPluginConstants.CMD_STOP ); setActionDefinitionId( LdapServersPluginConstants.CMD_STOP ); setToolTipText( Messages.getString( "StopAction.StopToolTip" ) ); //$NON-NLS-1$ setImageDescriptor( LdapServersPlugin.getDefault().getImageDescriptor( LdapServersPluginConstants.IMG_STOP ) ); } /** * {@inheritDoc} */ public void run() { if ( view != null ) { // Getting the selection StructuredSelection selection = ( StructuredSelection ) view.getViewer().getSelection(); if ( ( !selection.isEmpty() ) && ( selection.size() == 1 ) ) { // Getting the server LdapServer server = ( LdapServer ) selection.getFirstElement(); // Creating and scheduling the job to stop the server StudioLdapServerJob job = new StudioLdapServerJob( new StopLdapServerRunnable( server ) ); job.schedule(); } } } /** * {@inheritDoc} */ public void run( IAction action ) { run(); } /** * {@inheritDoc} */ public void dispose() { // Nothing to do } /** * {@inheritDoc} */ public void init( IWorkbenchWindow window ) { // Nothing to do } /** * {@inheritDoc} */ public void selectionChanged( IAction action, ISelection 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/ldapservers/src/main/java/org/apache/directory/studio/ldapservers/actions/PropertiesAction.java
plugins/ldapservers/src/main/java/org/apache/directory/studio/ldapservers/actions/PropertiesAction.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.ldapservers.actions; import org.apache.directory.studio.ldapservers.LdapServersPluginConstants; import org.apache.directory.studio.ldapservers.model.LdapServer; import org.apache.directory.studio.ldapservers.views.ServersView; import org.eclipse.jface.action.Action; import org.eclipse.jface.action.IAction; import org.eclipse.jface.preference.PreferenceDialog; import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.StructuredSelection; import org.eclipse.osgi.util.NLS; import org.eclipse.ui.IWorkbenchWindow; import org.eclipse.ui.IWorkbenchWindowActionDelegate; import org.eclipse.ui.dialogs.PreferencesUtil; /** * This class implements the properties action for a server. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class PropertiesAction extends Action implements IWorkbenchWindowActionDelegate { /** The associated view */ private ServersView view; /** * Creates a new instance of PropertiesAction. */ public PropertiesAction() { super( Messages.getString( "PropertiesAction.Properties" ) ); //$NON-NLS-1$ init(); } /** * Creates a new instance of PropertiesAction. * * @param view * the associated view */ public PropertiesAction( ServersView view ) { super( Messages.getString( "PropertiesAction.Properties" ) ); //$NON-NLS-1$ this.view = view; init(); } /** * Initializes the action. */ private void init() { setId( LdapServersPluginConstants.CMD_PROPERTIES ); setActionDefinitionId( LdapServersPluginConstants.CMD_PROPERTIES ); setToolTipText( Messages.getString( "PropertiesAction.PropertiesToolTip" ) ); //$NON-NLS-1$ } /** * {@inheritDoc} */ public void run() { if ( view != null ) { StructuredSelection selection = ( StructuredSelection ) view.getViewer().getSelection(); if ( !selection.isEmpty() ) { LdapServer server = ( LdapServer ) selection.getFirstElement(); PreferenceDialog dialog = PreferencesUtil.createPropertyDialogOn( view.getViewSite().getShell(), server, LdapServersPluginConstants.PROP_SERVER_PROPERTY_PAGE, null, null ); dialog.getShell().setText( NLS.bind( Messages.getString( "PropertiesAction.PropertiesFor" ), //$NON-NLS-1$ shorten( server.getName(), 30 ) ) ); dialog.open(); } } } /** * Shortens the given label to the given maximum length * and filters non-printable characters. * * @param label the label * @param maxLength the max length * * @return the shortened label */ public static String shorten( String label, int maxLength ) { if ( label == null ) { return null; } // shorten label if ( maxLength < 3 ) { return "..."; //$NON-NLS-1$ } if ( label.length() > maxLength ) { label = label.substring( 0, maxLength / 2 ) + "..." //$NON-NLS-1$ + label.substring( label.length() - maxLength / 2, label.length() ); } // filter non-printable characters StringBuffer sb = new StringBuffer( maxLength + 3 ); for ( int i = 0; i < label.length(); i++ ) { char c = label.charAt( i ); if ( Character.isISOControl( c ) ) { sb.append( '.' ); } else { sb.append( c ); } } return sb.toString(); } /** * {@inheritDoc} */ public void run( IAction action ) { run(); } /** * {@inheritDoc} */ public void dispose() { // Nothing to do } /** * {@inheritDoc} */ public void init( IWorkbenchWindow window ) { // Nothing to do } /** * {@inheritDoc} */ public void selectionChanged( IAction action, ISelection 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/ldapservers/src/main/java/org/apache/directory/studio/ldapservers/actions/Messages.java
plugins/ldapservers/src/main/java/org/apache/directory/studio/ldapservers/actions/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.ldapservers.actions; 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/ldapservers/src/main/java/org/apache/directory/studio/ldapservers/actions/OpenConfigurationAction.java
plugins/ldapservers/src/main/java/org/apache/directory/studio/ldapservers/actions/OpenConfigurationAction.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.ldapservers.actions; import org.apache.directory.studio.ldapservers.LdapServersPluginConstants; import org.apache.directory.studio.ldapservers.jobs.OpenConfigurationLdapServerRunnable; import org.apache.directory.studio.ldapservers.jobs.StudioLdapServerJob; import org.apache.directory.studio.ldapservers.model.LdapServer; import org.apache.directory.studio.ldapservers.views.ServersView; import org.eclipse.jface.action.Action; import org.eclipse.jface.action.IAction; import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.StructuredSelection; import org.eclipse.ui.IWorkbenchWindow; import org.eclipse.ui.IWorkbenchWindowActionDelegate; /** * This class implements the open action for a server. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class OpenConfigurationAction extends Action implements IWorkbenchWindowActionDelegate { /** The associated view */ private ServersView view; /** * Creates a new instance of OpenConfigurationAction. */ public OpenConfigurationAction() { super( Messages.getString( "OpenConfigurationAction.OpenConfiguration" ) ); //$NON-NLS-1$ init(); } /** * Creates a new instance of OpenConfigurationAction. * * @param view * the associated view */ public OpenConfigurationAction( ServersView view ) { super( Messages.getString( "OpenConfigurationAction.OpenConfiguration" ) ); //$NON-NLS-1$ this.view = view; init(); } /** * Initializes the action. */ private void init() { setId( LdapServersPluginConstants.CMD_OPEN_CONFIGURATION ); setActionDefinitionId( LdapServersPluginConstants.CMD_OPEN_CONFIGURATION ); setToolTipText( Messages.getString( "OpenConfigurationAction.OpenConfigurationToolTip" ) ); //$NON-NLS-1$ } /** * {@inheritDoc} */ public void run() { if ( view != null ) { // Getting the selection StructuredSelection selection = ( StructuredSelection ) view.getViewer().getSelection(); if ( ( !selection.isEmpty() ) && ( selection.size() == 1 ) ) { // Getting the server LdapServer server = ( LdapServer ) selection.getFirstElement(); // Creating and scheduling the job to start the server StudioLdapServerJob job = new StudioLdapServerJob( new OpenConfigurationLdapServerRunnable( server ) ); job.schedule(); } } } /** * {@inheritDoc} */ public void run( IAction action ) { run(); } /** * {@inheritDoc} */ public void dispose() { // Nothing to do } /** * {@inheritDoc} */ public void init( IWorkbenchWindow window ) { // Nothing to do } /** * {@inheritDoc} */ public void selectionChanged( IAction action, ISelection 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/ldapservers/src/main/java/org/apache/directory/studio/ldapservers/actions/StartAction.java
plugins/ldapservers/src/main/java/org/apache/directory/studio/ldapservers/actions/StartAction.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.ldapservers.actions; import org.apache.directory.studio.ldapservers.LdapServersPlugin; import org.apache.directory.studio.ldapservers.LdapServersPluginConstants; import org.apache.directory.studio.ldapservers.jobs.StartLdapServerRunnable; import org.apache.directory.studio.ldapservers.jobs.StudioLdapServerJob; import org.apache.directory.studio.ldapservers.model.LdapServer; import org.apache.directory.studio.ldapservers.model.LdapServerAdapter; import org.apache.directory.studio.ldapservers.model.LdapServerAdapterExtension; import org.apache.directory.studio.ldapservers.views.ServersView; import org.eclipse.jface.action.Action; import org.eclipse.jface.action.IAction; import org.eclipse.jface.dialogs.IDialogConstants; import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.StructuredSelection; import org.eclipse.osgi.util.NLS; import org.eclipse.ui.IWorkbenchWindow; import org.eclipse.ui.IWorkbenchWindowActionDelegate; /** * This class implements the start action for a server. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class StartAction extends Action implements IWorkbenchWindowActionDelegate { /** The associated view */ private ServersView view; /** * Creates a new instance of StartAction. */ public StartAction() { super( Messages.getString( "StartAction.Start" ) ); //$NON-NLS-1$ init(); } /** * Creates a new instance of StartAction. * * @param view * the associated view */ public StartAction( ServersView view ) { super( Messages.getString( "StartAction.Start" ) ); //$NON-NLS-1$ this.view = view; init(); } /** * Initializes the action. */ private void init() { setId( LdapServersPluginConstants.CMD_START ); setActionDefinitionId( LdapServersPluginConstants.CMD_START ); setToolTipText( Messages.getString( "StartAction.StartToolTip" ) ); //$NON-NLS-1$ setImageDescriptor( LdapServersPlugin.getDefault().getImageDescriptor( LdapServersPluginConstants.IMG_START ) ); } /** * {@inheritDoc} */ public void run() { if ( view != null ) { // Getting the selection StructuredSelection selection = ( StructuredSelection ) view.getViewer().getSelection(); if ( ( !selection.isEmpty() ) && ( selection.size() == 1 ) ) { // Getting the server LdapServer server = ( LdapServer ) selection.getFirstElement(); LdapServerAdapterExtension ldapServerAdapterExtension = server.getLdapServerAdapterExtension(); if ( ( ldapServerAdapterExtension != null ) && ( ldapServerAdapterExtension.getInstance() != null ) ) { LdapServerAdapter ldapServerAdapter = ldapServerAdapterExtension.getInstance(); try { // Getting the ports already in use String[] portsAlreadyInUse = ldapServerAdapter.checkPortsBeforeServerStart( server ); if ( ( portsAlreadyInUse == null ) || ( portsAlreadyInUse.length > 0 ) ) { String title = null; String message = null; if ( portsAlreadyInUse.length == 1 ) { title = Messages.getString( "StartAction.PortInUse" ); //$NON-NLS-1$ message = NLS .bind( Messages.getString( "StartAction.PortOfProtocolInUse" ), new String[] { portsAlreadyInUse[0] } ); //$NON-NLS-1$ } else { title = Messages.getString( "StartAction.PortsInUse" ); //$NON-NLS-1$ message = Messages.getString( "StartAction.PortsOfProtocolsInUse" ); //$NON-NLS-1$ for ( String portAlreadyInUse : portsAlreadyInUse ) { message += "\n - " + portAlreadyInUse; //$NON-NLS-1$ } } message += "\n\n" + Messages.getString( "StartAction.Continue" ); //$NON-NLS-1$ //$NON-NLS-2$ MessageDialog dialog = new MessageDialog( view.getSite().getShell(), title, null, message, MessageDialog.WARNING, new String[] { IDialogConstants.OK_LABEL, IDialogConstants.CANCEL_LABEL }, MessageDialog.OK ); if ( dialog.open() == MessageDialog.CANCEL ) { return; } } // Creating and scheduling the job to start the server StudioLdapServerJob job = new StudioLdapServerJob( new StartLdapServerRunnable( server ) ); job.schedule(); } catch ( Exception e ) { // Showing an error in case no LDAP Server Adapter can be found MessageDialog .openError( view.getSite().getShell(), Messages.getString( "StartAction.ErrorStartingServer" ), //$NON-NLS-1$ NLS.bind( Messages.getString( "StartAction.ServerCanNotBeStarted" ) + "\n" + Messages.getString( "StartAction.Cause" ), server.getName(), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ e.getMessage() ) ); } } else { // Showing an error in case no LDAP Server Adapter can be found MessageDialog.openError( view.getSite().getShell(), Messages.getString( "StartAction.NoLdapServerAdapter" ), //$NON-NLS-1$ NLS.bind( Messages.getString( "StartAction.ServerCanNotBeStarted" ) + "\n" //$NON-NLS-1$ //$NON-NLS-2$ + Messages.getString( "StartAction.NoLdapServerAdapterCouldBeFound" ), server.getName() ) ); //$NON-NLS-1$ } } } } /** * {@inheritDoc} */ public void run( IAction action ) { run(); } /** * {@inheritDoc} */ public void dispose() { // Nothing to do } /** * {@inheritDoc} */ public void init( IWorkbenchWindow window ) { // Nothing to do } /** * {@inheritDoc} */ public void selectionChanged( IAction action, ISelection 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/ldapservers/src/main/java/org/apache/directory/studio/ldapservers/properties/ServerPropertyPage.java
plugins/ldapservers/src/main/java/org/apache/directory/studio/ldapservers/properties/ServerPropertyPage.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.ldapservers.properties; import org.apache.directory.studio.common.ui.widgets.BaseWidgetUtils; import org.apache.directory.studio.ldapservers.LdapServersManager; import org.apache.directory.studio.ldapservers.model.LdapServer; import org.apache.directory.studio.ldapservers.model.LdapServerAdapterExtension; import org.eclipse.swt.SWT; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Text; import org.eclipse.ui.IWorkbenchPropertyPage; import org.eclipse.ui.dialogs.PropertyPage; /** * This class implements the Info property page for an LDAP server. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class ServerPropertyPage extends PropertyPage implements IWorkbenchPropertyPage { /** * Creates a new instance of ServerPropertyPage. */ public ServerPropertyPage() { super(); super.noDefaultAndApplyButton(); } /** * {@inheritDoc} */ protected Control createContents( Composite parent ) { // Composite Composite composite = BaseWidgetUtils.createColumnContainer( parent, 2, 1 ); // Name BaseWidgetUtils.createLabel( composite, Messages.getString( "ServerPropertyPage.Name" ), 1 ); //$NON-NLS-1$ Text nameText = BaseWidgetUtils.createLabeledText( composite, "", 1 ); //$NON-NLS-1$ // Type BaseWidgetUtils.createLabel( composite, Messages.getString( "ServerPropertyPage.Type" ), 1 ); //$NON-NLS-1$ Text typeText = BaseWidgetUtils.createLabeledText( composite, "", 1 ); //$NON-NLS-1$ // Vendor BaseWidgetUtils.createLabel( composite, Messages.getString( "ServerPropertyPage.Vendor" ), 1 ); //$NON-NLS-1$ Text vendorText = BaseWidgetUtils.createLabeledText( composite, "", 1 ); //$NON-NLS-1$ // Location Label locationLabel = BaseWidgetUtils.createLabel( composite, Messages.getString( "ServerPropertyPage.Location" ), 1 ); //$NON-NLS-1$ locationLabel.setLayoutData( new GridData( SWT.NONE, SWT.TOP, false, false ) ); Text locationText = BaseWidgetUtils.createWrappedLabeledText( composite, "", 1 ); //$NON-NLS-1$ GridData gd = new GridData( SWT.FILL, SWT.NONE, true, false ); gd.widthHint = 300; locationText.setLayoutData( gd ); // Getting the server LdapServer server = ( LdapServer ) getElement(); if ( server != null ) { LdapServerAdapterExtension ldapServerAdapterExtension = server.getLdapServerAdapterExtension(); nameText.setText( server.getName() ); typeText.setText( ldapServerAdapterExtension.getName() + " " + ldapServerAdapterExtension.getVersion() ); //$NON-NLS-1$ vendorText.setText( ldapServerAdapterExtension.getVendor() ); locationText.setText( LdapServersManager.getServersFolder().append( server.getId() ).toOSString() ); } return parent; } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/ldapservers/src/main/java/org/apache/directory/studio/ldapservers/properties/Messages.java
plugins/ldapservers/src/main/java/org/apache/directory/studio/ldapservers/properties/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.ldapservers.properties; 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/ldapservers/src/main/java/org/apache/directory/studio/ldapservers/properties/ServerPropertyConfigurationPage.java
plugins/ldapservers/src/main/java/org/apache/directory/studio/ldapservers/properties/ServerPropertyConfigurationPage.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.ldapservers.properties; import org.apache.directory.studio.ldapservers.LdapServersManager; import org.apache.directory.studio.ldapservers.model.LdapServer; import org.apache.directory.studio.ldapservers.model.LdapServerAdapterConfigurationPage; import org.apache.directory.studio.ldapservers.model.LdapServerAdapterConfigurationPageModifyListener; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; import org.eclipse.ui.IWorkbenchPropertyPage; import org.eclipse.ui.dialogs.PropertyPage; /** * This class implements the Configuration property page for an LDAP server. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class ServerPropertyConfigurationPage extends PropertyPage implements IWorkbenchPropertyPage, LdapServerAdapterConfigurationPageModifyListener { /** The LDAP server*/ private LdapServer ldapServer; /** The configuration page */ private LdapServerAdapterConfigurationPage configurationPage; /** * Creates a new instance of ServerPropertyPage. */ public ServerPropertyConfigurationPage() { super(); super.noDefaultAndApplyButton(); } /** * {@inheritDoc} */ protected Control createContents( Composite parent ) { // Getting the server ldapServer = ( LdapServer ) getElement(); if ( ldapServer != null ) { configurationPage = ldapServer.getLdapServerAdapterExtension() .getNewConfigurationPageInstance(); configurationPage.setModifyListener( this ); Control control = configurationPage.createControl( parent ); configurationPage.loadConfiguration( ldapServer ); return control; } return parent; } /** * {@inheritDoc} */ public void configurationPageModified() { if ( ldapServer != null ) { setErrorMessage( configurationPage.getErrorMessage() ); setValid( configurationPage.isPageComplete() ); } } /** * {@inheritDoc} */ public boolean performOk() { if ( ldapServer != null ) { // Saving the configuration configurationPage.saveConfiguration( ldapServer ); // Saving the server to the file store. LdapServersManager.getDefault().saveServersToStore(); } return super.performOk(); } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/ldapservers/src/main/java/org/apache/directory/studio/ldapservers/views/ServersTableViewer.java
plugins/ldapservers/src/main/java/org/apache/directory/studio/ldapservers/views/ServersTableViewer.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.ldapservers.views; import java.util.ArrayList; import java.util.Comparator; import java.util.List; import org.apache.directory.studio.ldapservers.LdapServersManager; import org.apache.directory.studio.ldapservers.LdapServersManagerListener; import org.apache.directory.studio.ldapservers.model.LdapServer; import org.apache.directory.studio.ldapservers.model.LdapServerEvent; import org.apache.directory.studio.ldapservers.model.LdapServerEventType; import org.apache.directory.studio.ldapservers.model.LdapServerListener; import org.apache.directory.studio.ldapservers.model.LdapServerStatus; import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.TreeViewer; import org.eclipse.jface.viewers.ViewerComparator; import org.eclipse.swt.SWT; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Tree; import org.eclipse.swt.widgets.TreeColumn; import org.eclipse.swt.widgets.TreeItem; import org.eclipse.swt.widgets.Widget; import org.eclipse.ui.PlatformUI; /** * This class implements a {@link TreeViewer} that displays the servers. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class ServersTableViewer extends TreeViewer { /** The root element */ protected static final String ROOT = "root"; //$NON-NLS-1$ /** The label provider */ private ServersViewLabelProvider labelProvider; /** The comparator */ private ServersComparator comparator; /** The server handler listener */ private LdapServersManagerListener serversHandlerListener; /** The server listener */ private LdapServerListener serverListener; /** A flag to stop the animation */ private boolean stopAnimation; /** The list of server needing animation */ private List<LdapServer> serversNeedingAnimation = new ArrayList<LdapServer>(); /** * Creates a new instance of ServersTableViewer. * * @param tree * the associated tree */ public ServersTableViewer( Tree tree ) { super( tree ); labelProvider = new ServersViewLabelProvider(); setLabelProvider( labelProvider ); setContentProvider( new ServersViewContentProvider() ); comparator = new ServersComparator(); setComparator( new ViewerComparator( comparator ) ); setInput( ROOT ); addListeners(); } /** * Adds the listener */ private void addListeners() { // The server handler listener serversHandlerListener = new LdapServersManagerListener() { public void serverAdded( LdapServer server ) { addServer( server ); server.addListener( serverListener ); } public void serverRemoved( LdapServer server ) { refreshServer( server ); } public void serverUpdated( LdapServer server ) { removeServer( server ); server.removeListener( serverListener ); } }; // Adding the listener to the servers handler LdapServersManager.getDefault().addListener( serversHandlerListener ); // The server listener serverListener = new LdapServerListener() { public void serverChanged( LdapServerEvent event ) { // Checking if the event is null if ( event == null ) { return; } // Getting the kind of event and the associated server LdapServerEventType kind = event.getKind(); LdapServer server = event.getServer(); switch ( kind ) { // The server status has changed case STATUS_CHANGED: // First, we refresh the server refreshServer( server ); // Then, we get the status of the server to see if we // need to start or stop the animation thread LdapServerStatus state = server.getStatus(); // If the state is STARTING or STOPPING, we need to // add the server to the list of servers needing // animation and eventually start the animation thread if ( ( state == LdapServerStatus.STARTING ) || ( state == LdapServerStatus.STOPPING ) || ( state == LdapServerStatus.REPAIRING ) ) { boolean startAnimationThread = false; synchronized ( serversNeedingAnimation ) { if ( !serversNeedingAnimation.contains( server ) ) { if ( serversNeedingAnimation.isEmpty() ) startAnimationThread = true; serversNeedingAnimation.add( server ); } } if ( startAnimationThread ) { startAnimationThread(); } } // If the state is *not* STARTING or STOPPING, we need // to remove the server from the list of servers // needing animation and eventually stop the animation // if this list is empty else { boolean stopAnimationThread = false; synchronized ( serversNeedingAnimation ) { if ( serversNeedingAnimation.contains( server ) ) { serversNeedingAnimation.remove( server ); if ( serversNeedingAnimation.isEmpty() ) stopAnimationThread = true; } } if ( stopAnimationThread ) { stopAnimationThread(); } } break; // The server has been renamed case RENAMED: // We simply refresh the server refreshServer( server ); break; } } }; // Adding the listener to the servers for ( LdapServer server : LdapServersManager.getDefault().getServersList() ) { server.addListener( serverListener ); } } /** * Adds a server. * * @param server * the server */ private void addServer( final LdapServer server ) { Display.getDefault().asyncExec( new Runnable() { public void run() { add( ROOT, server ); } } ); } /** * Refreshes a server. * * @param server * the server */ private void refreshServer( final LdapServer server ) { Display.getDefault().asyncExec( new Runnable() { public void run() { refresh( server ); ISelection sel = ServersTableViewer.this.getSelection(); ServersTableViewer.this.setSelection( sel ); } } ); } /** * Removes a server. * * @param server * the server */ private void removeServer( final LdapServer server ) { Display.getDefault().asyncExec( new Runnable() { public void run() { remove( server ); } } ); } /** * Starts the animation thread. */ private void startAnimationThread() { stopAnimation = false; final Display display = getTree().getDisplay(); final int SLEEP = 200; final Runnable[] animatorThread = new Runnable[1]; animatorThread[0] = new Runnable() { public void run() { // Checking if we need to stop the animation if ( !stopAnimation ) { // Changing the animation state on the label provider labelProvider.animate(); // Looping on the currently starting servers for ( LdapServer server : serversNeedingAnimation.toArray( new LdapServer[0] ) ) { if ( server != null && getTree() != null && !getTree().isDisposed() ) { updateAnimation( server ); } } // Re-launching the animation display.timerExec( SLEEP, animatorThread[0] ); } } }; // Launching the animation asynchronously Display.getDefault().asyncExec( new Runnable() { public void run() { display.timerExec( SLEEP, animatorThread[0] ); } } ); } /** * Stops the animation thread. */ private void stopAnimationThread() { stopAnimation = true; } /** * Updates the animation for the given server * * @param server * the server */ private void updateAnimation( LdapServer server ) { Widget widget = doFindItem( server ); TreeItem item = ( TreeItem ) widget; item.setText( 1, labelProvider.getColumnText( server, 1 ) ); item.setImage( 1, labelProvider.getColumnImage( server, 1 ) ); } /** * Sorts the table. * * @param treeColumn the tree column * @param column the column number */ public void sort( final TreeColumn treeColumn, int column ) { if ( column == comparator.column ) { comparator.reverseOrdering(); } else { comparator.column = column; } PlatformUI.getWorkbench().getDisplay().asyncExec( new Runnable() { public void run() { refresh(); Tree tree = getTree(); tree.setSortColumn( treeColumn ); if ( comparator.order == ServersComparator.ASCENDING ) { tree.setSortDirection( SWT.UP ); } else { tree.setSortDirection( SWT.DOWN ); } } } ); } /** * This class implements a comparator for servers. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ private class ServersComparator implements Comparator<Object> { public static final int ASCENDING = 1; /** The comparison order */ int order = ASCENDING; /** The column used to compare objects */ int column = 0; /** * Reverses the order. */ public void reverseOrdering() { order = order * -1; } /** * {@inheritDoc} */ public int compare( Object o1, Object o2 ) { String s1 = labelProvider.getColumnText( o1, column ); String s2 = labelProvider.getColumnText( o2, column ); return s1.compareToIgnoreCase( s2 ) * order; } } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/ldapservers/src/main/java/org/apache/directory/studio/ldapservers/views/Messages.java
plugins/ldapservers/src/main/java/org/apache/directory/studio/ldapservers/views/Messages.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.ldapservers.views; import java.util.MissingResourceException; import java.util.ResourceBundle; /** * This class get messages from the resources file. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class Messages { /** The resource name */ private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle.getBundle( Messages.class.getPackage().getName() + ".messages" ); /** * Get back a message from the resource file given a key * * @param key The key associated with the message * @return The found message */ public static String getString( String key ) { try { return RESOURCE_BUNDLE.getString( key ); } catch ( MissingResourceException e ) { return '!' + key + '!'; } } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/ldapservers/src/main/java/org/apache/directory/studio/ldapservers/views/ServersViewContentProvider.java
plugins/ldapservers/src/main/java/org/apache/directory/studio/ldapservers/views/ServersViewContentProvider.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.ldapservers.views; import org.apache.directory.studio.ldapservers.LdapServersManager; import org.eclipse.jface.viewers.IStructuredContentProvider; import org.eclipse.jface.viewers.ITreeContentProvider; import org.eclipse.jface.viewers.Viewer; /** * This class implements the content provider for the Servers view. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class ServersViewContentProvider implements IStructuredContentProvider, ITreeContentProvider { /** * {@inheritDoc} */ public Object[] getElements( Object inputElement ) { return LdapServersManager.getDefault().getServersList().toArray(); } /** * {@inheritDoc} */ public void dispose() { // Nothing to do } /** * {@inheritDoc} */ public void inputChanged( Viewer viewer, Object oldInput, Object newInput ) { // Nothing to do } /** * {@inheritDoc} */ public Object[] getChildren( Object parentElement ) { return null; } /** * {@inheritDoc} */ public Object getParent( Object element ) { return null; } /** * {@inheritDoc} */ public boolean hasChildren( Object element ) { 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/ldapservers/src/main/java/org/apache/directory/studio/ldapservers/views/ServersView.java
plugins/ldapservers/src/main/java/org/apache/directory/studio/ldapservers/views/ServersView.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.ldapservers.views; import org.apache.directory.studio.ldapservers.LdapServersManager; import org.apache.directory.studio.ldapservers.LdapServersManagerListener; import org.apache.directory.studio.ldapservers.LdapServersPluginConstants; import org.apache.directory.studio.ldapservers.actions.DeleteAction; import org.apache.directory.studio.ldapservers.actions.NewServerAction; import org.apache.directory.studio.ldapservers.actions.OpenConfigurationAction; import org.apache.directory.studio.ldapservers.actions.PropertiesAction; import org.apache.directory.studio.ldapservers.actions.RenameAction; import org.apache.directory.studio.ldapservers.actions.StartAction; import org.apache.directory.studio.ldapservers.actions.StopAction; import org.apache.directory.studio.ldapservers.model.LdapServer; import org.eclipse.jface.action.IMenuListener; 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.commands.ActionHandler; 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.TreeViewer; import org.eclipse.swt.SWT; 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.widgets.Composite; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Tree; import org.eclipse.swt.widgets.TreeColumn; import org.eclipse.ui.IMemento; import org.eclipse.ui.IPartListener2; import org.eclipse.ui.IViewSite; import org.eclipse.ui.IWorkbenchActionConstants; import org.eclipse.ui.IWorkbenchPartReference; import org.eclipse.ui.PartInitException; import org.eclipse.ui.PlatformUI; import org.eclipse.ui.commands.ICommandService; import org.eclipse.ui.contexts.IContextActivation; import org.eclipse.ui.contexts.IContextService; import org.eclipse.ui.part.ViewPart; /** * This class implements the Servers view. * <p> * It displays the list of Apache Directory Servers. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class ServersView extends ViewPart { /** The ID of the view */ // public static final String ID = ApacheDsPluginConstants.VIEW_SERVERS_VIEW; // TODO /** The tree*/ private Tree tree; /** The table viewer */ private ServersTableViewer tableViewer; /** The view instance */ private ServersView instance; /** Token used to activate and deactivate shortcuts in the view */ private IContextActivation contextActivation; private static final String TAG_COLUMN_WIDTH = "columnWidth"; //$NON-NLS-1$ protected int[] columnWidths; // Actions private NewServerAction newServer; private OpenConfigurationAction openConfiguration; private DeleteAction delete; private RenameAction rename; private StartAction start; private StopAction stop; private PropertiesAction properties; // Listeners private LdapServersManagerListener ldapServersManagerListener = new LdapServersManagerListener() { public void serverAdded( LdapServer server ) { asyncRefresh(); } public void serverRemoved( LdapServer server ) { asyncRefresh(); } public void serverUpdated( LdapServer server ) { asyncRefresh(); } }; /** * {@inheritDoc} */ public void createPartControl( Composite parent ) { instance = this; // Creating the Tree tree = new Tree( parent, SWT.SINGLE | SWT.FULL_SELECTION | SWT.H_SCROLL | SWT.V_SCROLL ); tree.setLayoutData( new GridData( SWT.FILL, SWT.FILL, true, true ) ); tree.setHeaderVisible( true ); tree.setLinesVisible( false ); // Adding columns TreeColumn serverColumn = new TreeColumn( tree, SWT.SINGLE ); serverColumn.setText( Messages.getString( "ServersView.server" ) ); //$NON-NLS-1$ serverColumn.setWidth( columnWidths[0] ); serverColumn.addSelectionListener( getColumnSelectionListener( 0 ) ); tree.setSortColumn( serverColumn ); tree.setSortDirection( SWT.UP ); TreeColumn stateColumn = new TreeColumn( tree, SWT.SINGLE ); stateColumn.setText( Messages.getString( "ServersView.state" ) ); //$NON-NLS-1$ stateColumn.setWidth( columnWidths[1] ); stateColumn.addSelectionListener( getColumnSelectionListener( 1 ) ); // Creating the viewer tableViewer = new ServersTableViewer( tree ); initActions(); initToolbar(); initContextMenu(); initListeners(); // set help context // TODO // PlatformUI.getWorkbench().getHelpSystem() // .setHelp( parent, ApacheDsPluginConstants.PLUGIN_ID + "." + "gettingstarted_views_servers" ); //$NON-NLS-1$ //$NON-NLS-2$ } /** * {@inheritDoc} */ public void init( IViewSite site, IMemento memento ) throws PartInitException { super.init( site, memento ); columnWidths = new int[] { 150, 80 }; for ( int i = 0; i < 2; i++ ) { if ( memento != null ) { Integer in = memento.getInteger( TAG_COLUMN_WIDTH + i ); if ( in != null && in.intValue() > 5 ) { columnWidths[i] = in.intValue(); } } } } /** * {@inheritDoc} */ public void saveState( IMemento memento ) { TreeColumn[] tc = tableViewer.getTree().getColumns(); for ( int i = 0; i < 2; i++ ) { int width = tc[i].getWidth(); if ( width != 0 ) { memento.putInteger( TAG_COLUMN_WIDTH + i, width ); } } } /** * {@inheritDoc} */ public void setFocus() { if ( tree != null ) { tree.setFocus(); } } /** * Initializes the actions. */ private void initActions() { newServer = new NewServerAction(); openConfiguration = new OpenConfigurationAction( this ); openConfiguration.setEnabled( false ); delete = new DeleteAction( this ); delete.setEnabled( false ); rename = new RenameAction( this ); rename.setEnabled( false ); start = new StartAction( this ); start.setEnabled( false ); stop = new StopAction( this ); stop.setEnabled( false ); properties = new PropertiesAction( this ); properties.setEnabled( false ); } /** * Initializes the toolbar. */ private void initToolbar() { IToolBarManager toolbar = getViewSite().getActionBars().getToolBarManager(); toolbar.add( newServer ); toolbar.add( new Separator() ); toolbar.add( start ); toolbar.add( stop ); } /** * Initializes the Context Menu. */ private void initContextMenu() { MenuManager contextMenu = new MenuManager( "" ); //$NON-NLS-1$ contextMenu.setRemoveAllWhenShown( true ); contextMenu.addMenuListener( new IMenuListener() { public void menuAboutToShow( IMenuManager manager ) { MenuManager newManager = new MenuManager( Messages.getString( "ServersView.new" ) ); //$NON-NLS-1$ newManager.add( newServer ); manager.add( newManager ); manager.add( openConfiguration ); manager.add( new Separator() ); manager.add( delete ); manager.add( rename ); manager.add( new Separator() ); manager.add( start ); manager.add( stop ); manager.add( new Separator() ); manager.add( new Separator( IWorkbenchActionConstants.MB_ADDITIONS ) ); manager.add( new Separator() ); manager.add( new Separator() ); manager.add( properties ); } } ); // set the context menu to the table viewer tableViewer.getControl().setMenu( contextMenu.createContextMenu( tableViewer.getControl() ) ); // register the context menu to enable extension actions getSite().registerContextMenu( contextMenu, tableViewer ); } /** * Initializes the listeners */ private void initListeners() { LdapServersManager serversHandler = LdapServersManager.getDefault(); serversHandler.addListener( ldapServersManagerListener ); tableViewer.addDoubleClickListener( new IDoubleClickListener() { public void doubleClick( DoubleClickEvent event ) { openConfiguration.run(); } } ); tableViewer.addSelectionChangedListener( new ISelectionChangedListener() { public void selectionChanged( SelectionChangedEvent event ) { updateActionsStates(); } } ); // Initializing the PartListener getSite().getPage().addPartListener( new IPartListener2() { /** * This implementation deactivates the shortcuts when the part is deactivated. */ public void partDeactivated( IWorkbenchPartReference partRef ) { if ( partRef.getPart( false ) == instance && contextActivation != null ) { ICommandService commandService = ( ICommandService ) PlatformUI.getWorkbench().getAdapter( ICommandService.class ); if ( commandService != null ) { commandService.getCommand( newServer.getActionDefinitionId() ).setHandler( null ); commandService.getCommand( openConfiguration.getActionDefinitionId() ).setHandler( null ); commandService.getCommand( delete.getActionDefinitionId() ).setHandler( null ); commandService.getCommand( rename.getActionDefinitionId() ).setHandler( null ); commandService.getCommand( start.getActionDefinitionId() ).setHandler( null ); commandService.getCommand( stop.getActionDefinitionId() ).setHandler( null ); commandService.getCommand( properties.getActionDefinitionId() ).setHandler( null ); } IContextService contextService = ( IContextService ) PlatformUI.getWorkbench().getAdapter( IContextService.class ); contextService.deactivateContext( contextActivation ); contextActivation = null; } } /** * This implementation activates the shortcuts when the part is activated. */ public void partActivated( IWorkbenchPartReference partRef ) { if ( partRef.getPart( false ) == instance ) { IContextService contextService = ( IContextService ) PlatformUI.getWorkbench().getAdapter( IContextService.class ); contextActivation = contextService .activateContext( LdapServersPluginConstants.CONTEXTS_SERVERS_VIEW ); ICommandService commandService = ( ICommandService ) PlatformUI.getWorkbench().getAdapter( ICommandService.class ); if ( commandService != null ) { commandService.getCommand( newServer.getActionDefinitionId() ).setHandler( new ActionHandler( newServer ) ); commandService.getCommand( openConfiguration.getActionDefinitionId() ).setHandler( new ActionHandler( openConfiguration ) ); commandService.getCommand( delete.getActionDefinitionId() ).setHandler( new ActionHandler( delete ) ); commandService.getCommand( rename.getActionDefinitionId() ).setHandler( new ActionHandler( rename ) ); commandService.getCommand( start.getActionDefinitionId() ).setHandler( new ActionHandler( start ) ); commandService.getCommand( stop.getActionDefinitionId() ) .setHandler( new ActionHandler( stop ) ); commandService.getCommand( properties.getActionDefinitionId() ).setHandler( new ActionHandler( properties ) ); } } } public void partBroughtToTop( IWorkbenchPartReference partRef ) { } public void partClosed( IWorkbenchPartReference partRef ) { } public void partHidden( IWorkbenchPartReference partRef ) { } public void partInputChanged( IWorkbenchPartReference partRef ) { } public void partOpened( IWorkbenchPartReference partRef ) { } public void partVisible( IWorkbenchPartReference partRef ) { } } ); } /** * Enables or disables the actions according to the current selection * in the viewer. */ public void updateActionsStates() { // Getting the selection StructuredSelection selection = ( StructuredSelection ) tableViewer.getSelection(); if ( !selection.isEmpty() ) { LdapServer server = ( LdapServer ) selection.getFirstElement(); switch ( server.getStatus() ) { case STARTED: start.setEnabled( false ); stop.setEnabled( true ); break; case REPAIRING: case STARTING: start.setEnabled( false ); stop.setEnabled( false ); break; case STOPPED: start.setEnabled( true ); stop.setEnabled( false ); break; case STOPPING: start.setEnabled( false ); stop.setEnabled( false ); break; case UNKNOWN: start.setEnabled( false ); stop.setEnabled( false ); break; } openConfiguration.setEnabled( server.getLdapServerAdapterExtension().isOpenConfigurationActionEnabled() ); delete.setEnabled( true ); rename.setEnabled( true ); properties.setEnabled( true ); } else { openConfiguration.setEnabled( false ); delete.setEnabled( false ); rename.setEnabled( false ); start.setEnabled( false ); stop.setEnabled( false ); properties.setEnabled( false ); } } /** * Gets the table viewer. * * @return * the table viewer */ public TreeViewer getViewer() { return tableViewer; } /** * {@inheritDoc} */ public void dispose() { LdapServersManager.getDefault().removeListener( ldapServersManagerListener ); super.dispose(); } /** * Refreshes the Servers View asynchronously. */ private void asyncRefresh() { Display.getDefault().asyncExec( new Runnable() { public void run() { tableViewer.refresh(); } } ); } private SelectionListener getColumnSelectionListener( final int column ) { return new SelectionAdapter() { public void widgetSelected( SelectionEvent e ) { TreeColumn treeColumn = ( TreeColumn ) e.widget; tableViewer.sort( treeColumn, column ); } }; } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/ldapservers/src/main/java/org/apache/directory/studio/ldapservers/views/ServersViewLabelProvider.java
plugins/ldapservers/src/main/java/org/apache/directory/studio/ldapservers/views/ServersViewLabelProvider.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.ldapservers.views; import org.apache.directory.studio.ldapservers.LdapServersPlugin; import org.apache.directory.studio.ldapservers.LdapServersPluginConstants; import org.apache.directory.studio.ldapservers.model.LdapServer; import org.apache.directory.studio.ldapservers.model.LdapServerStatus; import org.eclipse.jface.viewers.ITableLabelProvider; import org.eclipse.jface.viewers.LabelProvider; import org.eclipse.swt.graphics.Image; /** * This class implements the label provider for the Servers view. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class ServersViewLabelProvider extends LabelProvider implements ITableLabelProvider { // Static strings for dots private static final String THREE_DOTS = "..."; //$NON-NLS-1$ private static final String TWO_DOTS = ".."; //$NON-NLS-1$ private static final String ONE_DOT = "."; //$NON-NLS-1$ /** The counter used for dots */ private int dotsCount = 1; /** * {@inheritDoc} */ public String getColumnText( Object element, int columnIndex ) { if ( element instanceof LdapServer ) { LdapServer server = ( LdapServer ) element; if ( columnIndex == 0 ) { return server.getName(); } else if ( columnIndex == 1 ) { LdapServerStatus status = ( ( LdapServer ) element ).getStatus(); switch ( status ) { case STARTED: return Messages.getString( "ServersViewLabelProvider.Started" ); //$NON-NLS-1$ case STARTING: return Messages.getString( "ServersViewLabelProvider.Starting" ) + getDots(); //$NON-NLS-1$ case STOPPED: return Messages.getString( "ServersViewLabelProvider.Stopped" ); //$NON-NLS-1$ case STOPPING: return Messages.getString( "ServersViewLabelProvider.Stopping" ) + getDots(); //$NON-NLS-1$ case UNKNOWN: return Messages.getString( "ServersViewLabelProvider.Unknown" ); //$NON-NLS-1$ case REPAIRING: return Messages.getString( "ServersViewLabelProvider.Repairing" ) + getDots(); //$NON-NLS-1$ } } } return super.getText( element ); } /** * Gets the dotted string, based on the current dotsCount. * * @return * the dotted string, based on the current dotsCount */ private String getDots() { if ( dotsCount == 1 ) { return ServersViewLabelProvider.ONE_DOT; } else if ( dotsCount == 2 ) { return ServersViewLabelProvider.TWO_DOTS; } else { return ServersViewLabelProvider.THREE_DOTS; } } /** * {@inheritDoc} */ public Image getColumnImage( Object element, int columnIndex ) { if ( element instanceof LdapServer ) { if ( columnIndex == 0 ) { return LdapServersPlugin.getDefault().getImage( LdapServersPluginConstants.IMG_SERVER ); } else if ( columnIndex == 1 ) { switch ( ( ( LdapServer ) element ).getStatus() ) { case STARTED: return LdapServersPlugin.getDefault().getImage( LdapServersPluginConstants.IMG_SERVER_STARTED ); case REPAIRING: case STARTING: switch ( dotsCount ) { case 1: return LdapServersPlugin.getDefault().getImage( LdapServersPluginConstants.IMG_SERVER_STARTING1 ); case 2: return LdapServersPlugin.getDefault().getImage( LdapServersPluginConstants.IMG_SERVER_STARTING2 ); case 3: return LdapServersPlugin.getDefault().getImage( LdapServersPluginConstants.IMG_SERVER_STARTING3 ); } case STOPPED: return LdapServersPlugin.getDefault().getImage( LdapServersPluginConstants.IMG_SERVER_STOPPED ); case STOPPING: switch ( dotsCount ) { case 1: return LdapServersPlugin.getDefault().getImage( LdapServersPluginConstants.IMG_SERVER_STOPPING1 ); case 2: return LdapServersPlugin.getDefault().getImage( LdapServersPluginConstants.IMG_SERVER_STOPPING2 ); case 3: return LdapServersPlugin.getDefault().getImage( LdapServersPluginConstants.IMG_SERVER_STOPPING3 ); } case UNKNOWN: return LdapServersPlugin.getDefault().getImage( LdapServersPluginConstants.IMG_SERVER ); } } } return super.getImage( element ); } /** * Increase the counter of the animation. */ public void animate() { dotsCount++; if ( dotsCount > 3 ) { dotsCount = 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/ldapservers/src/main/java/org/apache/directory/studio/ldapservers/dialogs/DeleteServerDialog.java
plugins/ldapservers/src/main/java/org/apache/directory/studio/ldapservers/dialogs/DeleteServerDialog.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.ldapservers.dialogs; import org.apache.directory.studio.ldapservers.model.LdapServer; import org.eclipse.jface.dialogs.IDialogConstants; import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.osgi.util.NLS; import org.eclipse.swt.widgets.Shell; /** * Dialog that prompts a user to delete server(s) and/or server configuration(s). * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class DeleteServerDialog extends MessageDialog { /** The server */ protected LdapServer server; /** * Creates a new DeleteServerDialog. * * @param parentShell a shell * @param server * the server */ public DeleteServerDialog( Shell parentShell, LdapServer server ) { super( parentShell, Messages.getString( "DeleteServerDialog.DeleteServer" ), null, null, QUESTION, new String[] //$NON-NLS-1$ { IDialogConstants.OK_LABEL, IDialogConstants.CANCEL_LABEL }, OK ); if ( server == null ) { throw new IllegalArgumentException(); } this.server = server; message = NLS.bind( Messages.getString( "DeleteServerDialog.SureToDelete" ), server.getName() ); //$NON-NLS-1$ } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false