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/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/actions/ValueEditorPreferencesAction.java
plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/actions/ValueEditorPreferencesAction.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.ldapbrowser.common.actions; import org.apache.directory.studio.ldapbrowser.common.BrowserCommonConstants; import org.eclipse.jface.action.Action; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Shell; import org.eclipse.ui.dialogs.PreferencesUtil; /** * This Action opens the Value Editors Preference Page. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class ValueEditorPreferencesAction extends Action { /** * Creates a new instance of ValueEditorPreferencesAction. */ public ValueEditorPreferencesAction() { super.setText( Messages.getString( "ValueEditorPreferencesAction.Preferences" ) ); //$NON-NLS-1$ super.setToolTipText( Messages.getString( "ValueEditorPreferencesAction.Preferences" ) ); //$NON-NLS-1$ super.setEnabled( true ); } /** * {@inheritDoc} */ public void run() { Shell shell = Display.getCurrent().getActiveShell(); String pageId = BrowserCommonConstants.PREFERENCEPAGEID_VALUEEDITORS; PreferencesUtil.createPreferenceDialogOn( shell, pageId, new String[] { pageId }, null ).open(); } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/actions/DeleteAction.java
plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/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.ldapbrowser.common.actions; import java.util.Arrays; import java.util.Collection; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; import java.util.LinkedHashSet; import java.util.Map; import java.util.Set; import org.apache.directory.api.ldap.model.schema.AttributeType; import org.apache.directory.api.ldap.model.schema.ObjectClass; import org.apache.directory.studio.connection.core.StudioControl; import org.apache.directory.studio.ldapbrowser.common.dialogs.DeleteDialog; import org.apache.directory.studio.ldapbrowser.core.BrowserCoreConstants; import org.apache.directory.studio.ldapbrowser.core.jobs.DeleteEntriesRunnable; import org.apache.directory.studio.ldapbrowser.core.jobs.StudioBrowserJob; import org.apache.directory.studio.ldapbrowser.core.model.AttributeHierarchy; import org.apache.directory.studio.ldapbrowser.core.model.IAttribute; import org.apache.directory.studio.ldapbrowser.core.model.IBookmark; import org.apache.directory.studio.ldapbrowser.core.model.IEntry; import org.apache.directory.studio.ldapbrowser.core.model.IRootDSE; import org.apache.directory.studio.ldapbrowser.core.model.ISearch; import org.apache.directory.studio.ldapbrowser.core.model.ISearchResult; 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.ldapbrowser.core.utils.CompoundModification; import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.osgi.util.NLS; import org.eclipse.ui.ISharedImages; import org.eclipse.ui.PlatformUI; import org.eclipse.ui.texteditor.IWorkbenchActionDefinitionIds; /** * This Action implements the Delete Action. It deletes Connections, Entries, Searches, Bookmarks, Attributes or Values. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class DeleteAction extends BrowserAction { /** * {@inheritDoc} */ public String getText() { try { Collection<IEntry> entries = getEntries(); ISearch[] searches = getSearches(); IBookmark[] bookmarks = getBookmarks(); Collection<IValue> values = getValues(); if ( entries.size() > 0 && searches.length == 0 && bookmarks.length == 0 && values.size() == 0 ) { return entries.size() > 1 ? Messages.getString( "DeleteAction.DeleteEntries" ) : Messages.getString( "DeleteAction.DeleteEntry" ); //$NON-NLS-1$ //$NON-NLS-2$ } if ( searches.length > 0 && entries.size() == 0 && bookmarks.length == 0 && values.size() == 0 ) { return searches.length > 1 ? Messages.getString( "DeleteAction.DeleteSearches" ) : Messages.getString( "DeleteAction.DeleteSearch" ); //$NON-NLS-1$ //$NON-NLS-2$ } if ( bookmarks.length > 0 && entries.size() == 0 && searches.length == 0 && values.size() == 0 ) { return bookmarks.length > 1 ? Messages.getString( "DeleteAction.DeleteBookmarks" ) : Messages.getString( "DeleteAction.DeleteBookmark" ); //$NON-NLS-1$ //$NON-NLS-2$ } if ( values.size() > 0 && entries.size() == 0 && searches.length == 0 && bookmarks.length == 0 ) { return values.size() > 1 ? Messages.getString( "DeleteAction.DeleteValues" ) : Messages.getString( "DeleteAction.DeleteValue" ); //$NON-NLS-1$ //$NON-NLS-2$ } } catch ( Exception e ) { } return Messages.getString( "DeleteAction.Delete" ); //$NON-NLS-1$ } /** * {@inheritDoc} */ public ImageDescriptor getImageDescriptor() { return PlatformUI.getWorkbench().getSharedImages().getImageDescriptor( ISharedImages.IMG_TOOL_DELETE ); } /** * {@inheritDoc} */ public String getCommandId() { return IWorkbenchActionDefinitionIds.DELETE; } /** * {@inheritDoc} */ public void run() { try { Collection<IEntry> entries = getEntries(); ISearch[] searches = getSearches(); IBookmark[] bookmarks = getBookmarks(); Collection<IValue> values = getValues(); StringBuffer message = new StringBuffer(); boolean askForTreeDeleteControl = false; if ( entries.size() > 0 ) { appendEntriesWarnMessage( message, entries ); if ( entries.iterator().next().getBrowserConnection().getRootDSE() .isControlSupported( StudioControl.TREEDELETE_CONTROL.getOid() ) ) { askForTreeDeleteControl = true; } } if ( searches.length > 0 ) { appendSearchesWarnMessage( message, searches ); } if ( bookmarks.length > 0 ) { appendBookmarsWarnMessage( message, bookmarks ); } if ( values.size() > 0 ) { boolean emptyValuesOnly = true; for ( IValue value : values ) { if ( !value.isEmpty() ) { emptyValuesOnly = false; } } if ( !emptyValuesOnly ) { appendValuesWarnMessage( message, values ); } } DeleteDialog dialog = new DeleteDialog( getShell(), getText(), message.toString(), askForTreeDeleteControl ); if ( message.length() == 0 || dialog.open() == DeleteDialog.OK ) { if ( entries.size() > 0 ) { deleteEntries( entries, dialog.isUseTreeDeleteControl() ); } if ( searches.length > 0 ) { deleteSearches( searches ); } if ( bookmarks.length > 0 ) { deleteBookmarks( bookmarks ); } if ( values.size() > 0 ) { deleteValues( values ); } } } catch ( Exception e ) { } } /** * {@inheritDoc} */ public boolean isEnabled() { try { Collection<IEntry> entries = getEntries(); ISearch[] searches = getSearches(); IBookmark[] bookmarks = getBookmarks(); Collection<IValue> values = getValues(); return entries.size() + searches.length + bookmarks.length + values.size() > 0; } catch ( Exception e ) { //e.printStackTrace(); return false; } } /** * Gets the Entries. * * @return * the Entries * @throws Exception * when an Entry has parent Entries */ protected Collection<IEntry> getEntries() { LinkedHashSet<IEntry> entriesSet = new LinkedHashSet<IEntry>(); for ( IEntry entry : getSelectedEntries() ) { entriesSet.add( entry ); } for ( ISearchResult sr : getSelectedSearchResults() ) { entriesSet.add( sr.getEntry() ); } Iterator<IEntry> iterator = entriesSet.iterator(); while ( iterator.hasNext() ) { IEntry entry = iterator.next(); if ( entriesSet.contains( entry.getParententry() ) ) { iterator.remove(); } } return entriesSet; } /** * Appends the entries warn message. * * @param message the message * @param entries the entries */ protected void appendEntriesWarnMessage( StringBuffer message, Collection<IEntry> entries ) { for ( IEntry entry : entries ) { if ( entry instanceof IRootDSE ) { message.append( Messages.getString( "DeleteAction.DeleteRootDSE" ) ); //$NON-NLS-1$ message.append( BrowserCoreConstants.LINE_SEPARATOR ); message.append( BrowserCoreConstants.LINE_SEPARATOR ); } } if ( entries.size() <= 5 ) { message.append( entries.size() == 1 ? Messages.getString( "DeleteAction.DeleteEntryQuestion" ) //$NON-NLS-1$ : Messages.getString( "DeleteAction.DeleteEntriesQuestion" ) ); //$NON-NLS-1$ for ( IEntry entry : entries ) { message.append( BrowserCoreConstants.LINE_SEPARATOR ); message.append( " - " ); //$NON-NLS-1$ message.append( entry.getDn().getName() ); } } else { message.append( Messages.getString( "DeleteAction.DeleteSelectedEntriesQuestion" ) ); //$NON-NLS-1$ } message.append( BrowserCoreConstants.LINE_SEPARATOR ); message.append( BrowserCoreConstants.LINE_SEPARATOR ); } /** * Deletes Entries. * * @param entries the Entries to delete * @param useTreeDeleteControl true to use the tree delete control */ protected void deleteEntries( Collection<IEntry> entries, boolean useTreeDeleteControl ) { new StudioBrowserJob( new DeleteEntriesRunnable( entries, useTreeDeleteControl ) ).execute(); } /** * Gets the Searches * * @return * the Searches * @throws Exception */ protected ISearch[] getSearches() { return getSelectedSearches(); } protected void appendSearchesWarnMessage( StringBuffer message, ISearch[] searches ) { if ( searches.length <= 5 ) { message.append( searches.length == 1 ? Messages.getString( "DeleteAction.DeleteSearchQuestion" ) //$NON-NLS-1$ : Messages.getString( "DeleteAction.DeleteSearchesQuestion" ) ); //$NON-NLS-1$ for ( int i = 0; i < searches.length; i++ ) { message.append( BrowserCoreConstants.LINE_SEPARATOR ); message.append( " - " ); //$NON-NLS-1$ message.append( searches[i].getName() ); } } else { message.append( Messages.getString( "DeleteAction.DeleteSelectedSearchesQuestion" ) ); //$NON-NLS-1$ } message.append( BrowserCoreConstants.LINE_SEPARATOR ); message.append( BrowserCoreConstants.LINE_SEPARATOR ); } /** * Delete Searches * * @param searches * the Searches to delete */ protected void deleteSearches( ISearch[] searches ) { for ( ISearch search : searches ) { search.getBrowserConnection().getSearchManager().removeSearch( search ); } } /** * Get the Bookmarks * * @return * @throws Exception */ protected IBookmark[] getBookmarks() { return getSelectedBookmarks(); } protected void appendBookmarsWarnMessage( StringBuffer message, IBookmark[] bookmarks ) { if ( bookmarks.length <= 5 ) { message.append( bookmarks.length == 1 ? Messages.getString( "DeleteAction.DeleteBookmarkQuestion" ) //$NON-NLS-1$ : Messages.getString( "DeleteAction.DeleteBookmarksQuestion" ) ); //$NON-NLS-1$ for ( int i = 0; i < bookmarks.length; i++ ) { message.append( BrowserCoreConstants.LINE_SEPARATOR ); message.append( " - " ); //$NON-NLS-1$ message.append( bookmarks[i].getName() ); } } else { message.append( Messages.getString( "DeleteAction.DeleteSelectedBookmarksQuestion" ) ); //$NON-NLS-1$ } message.append( BrowserCoreConstants.LINE_SEPARATOR ); message.append( BrowserCoreConstants.LINE_SEPARATOR ); } /** * Delete Bookmarks * * @param bookmarks * the Bookmarks to delete */ protected void deleteBookmarks( IBookmark[] bookmarks ) { for ( IBookmark bookmark : bookmarks ) { bookmark.getBrowserConnection().getBookmarkManager().removeBookmark( bookmark ); } } /** * Gets the Values * * @return * the Values * @throws Exception */ protected Collection<IValue> getValues() throws Exception { Set<IValue> valueList = new LinkedHashSet<IValue>(); // add selected attributes for ( IAttribute attribute : getSelectedAttributes() ) { if ( attribute != null && attribute.getValueSize() > 0 ) { valueList.addAll( Arrays.asList( attribute.getValues() ) ); } } // add selected hierarchies for ( AttributeHierarchy ah : getSelectedAttributeHierarchies() ) { for ( IAttribute attribute : ah ) { if ( attribute != null && attribute.getValueSize() > 0 ) { valueList.addAll( Arrays.asList( attribute.getValues() ) ); } } } // add selected values, but not if there attributes are also selected for ( IValue value : getSelectedValues() ) { valueList.add( value ); } return valueList; } protected void appendValuesWarnMessage( StringBuffer message, Collection<IValue> values ) { Map<AttributeType, Integer> attributeNameToSelectedValuesCountMap = new HashMap<AttributeType, Integer>(); Set<ObjectClass> selectedObjectClasses = new HashSet<ObjectClass>(); for ( IValue value : values ) { String type = value.getAttribute().getType(); AttributeType atd = value.getAttribute().getAttributeTypeDescription(); AttributeHierarchy ah = value.getAttribute().getEntry().getAttributeWithSubtypes( type ); // check if (part of) Rdn is selected if ( value.isRdnPart() ) { message.append( NLS.bind( Messages.getString( "DeleteAction.DeletePartOfRDN" ), value.toString() ) ); //$NON-NLS-1$ message.append( BrowserCoreConstants.LINE_SEPARATOR ); message.append( BrowserCoreConstants.LINE_SEPARATOR ); } // check if a required objectClass is selected if ( value.getAttribute().isObjectClassAttribute() ) { selectedObjectClasses.add( value.getAttribute().getEntry().getBrowserConnection().getSchema() .getObjectClassDescription( value.getStringValue() ) ); } // check if ALL values of objectClass or a MUST attribute are selected if ( !attributeNameToSelectedValuesCountMap.containsKey( atd ) ) { attributeNameToSelectedValuesCountMap.put( atd, Integer.valueOf( 0 ) ); } int count = ( attributeNameToSelectedValuesCountMap.get( atd ) ).intValue() + 1; attributeNameToSelectedValuesCountMap.put( atd, Integer.valueOf( count ) ); if ( value.getAttribute().isObjectClassAttribute() && count >= ah.getValueSize() ) { message.append( Messages.getString( "DeleteAction.DeleteObjectClass" ) ); //$NON-NLS-1$ message.append( BrowserCoreConstants.LINE_SEPARATOR ); message.append( BrowserCoreConstants.LINE_SEPARATOR ); continue; } else if ( value.getAttribute().isMustAttribute() && count >= ah.getValueSize() ) { message.append( NLS.bind( Messages.getString( "DeleteAction.DeleteMust" ), type ) ); //$NON-NLS-1$ message.append( BrowserCoreConstants.LINE_SEPARATOR ); message.append( BrowserCoreConstants.LINE_SEPARATOR ); } // check if a value of an operational attribute is selected if ( !SchemaUtils.isModifiable( atd ) ) { message.append( NLS.bind( Messages.getString( "DeleteAction.DeleteNonModifiable" ), type ) ); //$NON-NLS-1$ message.append( BrowserCoreConstants.LINE_SEPARATOR ); message.append( BrowserCoreConstants.LINE_SEPARATOR ); continue; } } // check if a required objectClass is selected if ( values.size() > 0 && !selectedObjectClasses.isEmpty() ) { IEntry entry = values.iterator().next().getAttribute().getEntry(); Schema schema = entry.getBrowserConnection().getSchema(); // get remaining attributes Collection<ObjectClass> remainingObjectClasses = entry.getObjectClassDescriptions(); remainingObjectClasses.removeAll( selectedObjectClasses ); Set<AttributeType> remainingAttributeSet = new HashSet<AttributeType>(); for ( ObjectClass ocd : remainingObjectClasses ) { { Collection<String> mustAttrs = SchemaUtils.getMustAttributeTypeDescriptionNamesTransitive( ocd, schema ); for ( String mustAttr : mustAttrs ) { AttributeType atd = entry.getBrowserConnection().getSchema() .getAttributeTypeDescription( mustAttr ); remainingAttributeSet.add( atd ); } Collection<String> mayAttrs = SchemaUtils.getMayAttributeTypeDescriptionNamesTransitive( ocd, schema ); for ( String mayAttr : mayAttrs ) { AttributeType atd = entry.getBrowserConnection().getSchema() .getAttributeTypeDescription( mayAttr ); remainingAttributeSet.add( atd ); } } } // check against attributes IAttribute[] attributes = entry.getAttributes(); for ( IAttribute attribute : attributes ) { if ( attribute.isMayAttribute() || attribute.isMustAttribute() ) { if ( !remainingAttributeSet.contains( attribute.getAttributeTypeDescription() ) ) { message.append( NLS.bind( Messages.getString( "DeleteAction.DeleteNeededObjectClass" ), attribute.getDescription() ) ); //$NON-NLS-1$ message.append( BrowserCoreConstants.LINE_SEPARATOR ); message.append( BrowserCoreConstants.LINE_SEPARATOR ); } } } } if ( values.size() <= 5 ) { message.append( values.size() == 1 ? Messages.getString( "DeleteAction.DeleteAttributeQuestion" ) //$NON-NLS-1$ : Messages.getString( "DeleteAction.DeleteAttributesQuestion" ) ); //$NON-NLS-1$ for ( IValue value : values ) { message.append( BrowserCoreConstants.LINE_SEPARATOR ); message.append( " - " ); //$NON-NLS-1$ message.append( value.toString() ); } } else { message.append( Messages.getString( "DeleteAction.DeleteSelectedAttributesQuestion" ) ); //$NON-NLS-1$ } message.append( BrowserCoreConstants.LINE_SEPARATOR ); message.append( BrowserCoreConstants.LINE_SEPARATOR ); } /** * Deletes Attributes and Values * * @param values * the Values to delete */ protected void deleteValues( Collection<IValue> values ) { new CompoundModification().deleteValues( values ); } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/actions/RenameAction.java
plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/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.ldapbrowser.common.actions; import org.apache.directory.api.ldap.model.name.Rdn; import org.apache.directory.studio.ldapbrowser.common.dialogs.RenameEntryDialog; import org.apache.directory.studio.ldapbrowser.common.dialogs.SimulateRenameDialogImpl; import org.apache.directory.studio.ldapbrowser.core.jobs.RenameEntryRunnable; import org.apache.directory.studio.ldapbrowser.core.jobs.StudioBrowserJob; import org.apache.directory.studio.ldapbrowser.core.model.IBookmark; import org.apache.directory.studio.ldapbrowser.core.model.IEntry; import org.apache.directory.studio.ldapbrowser.core.model.IQuickSearch; import org.apache.directory.studio.ldapbrowser.core.model.ISearch; import org.apache.directory.studio.ldapbrowser.core.model.impl.RootDSE; import org.eclipse.jface.dialogs.Dialog; import org.eclipse.jface.dialogs.IInputValidator; import org.eclipse.jface.dialogs.InputDialog; import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.ui.texteditor.IWorkbenchActionDefinitionIds; /** * This Action renames Connections, Entries, Searches, or Bookmarks. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class RenameAction extends BrowserAction { /** * Creates a new instance of RenameAction. * */ public RenameAction() { super(); } /** * {@inheritDoc} */ public String getText() { IEntry[] entries = getEntries(); ISearch[] searches = getSearches(); IBookmark[] bookmarks = getBookmarks(); if ( entries.length == 1 && searches.length == 0 && bookmarks.length == 0 ) { return Messages.getString( "RenameAction.RenameEntry" ); //$NON-NLS-1$ } else if ( searches.length == 1 && entries.length == 0 && bookmarks.length == 0 ) { return Messages.getString( "RenameAction.RenameSearch" ); //$NON-NLS-1$ } else if ( bookmarks.length == 1 && entries.length == 0 && searches.length == 0 ) { return Messages.getString( "RenameAction.RenameBookmark" ); //$NON-NLS-1$ } else { return Messages.getString( "RenameAction.Rename" ); //$NON-NLS-1$ } } /** * {@inheritDoc} */ public ImageDescriptor getImageDescriptor() { return null; } /** * {@inheritDoc} */ public String getCommandId() { return IWorkbenchActionDefinitionIds.RENAME; } /** * {@inheritDoc} */ public void run() { IEntry[] entries = getEntries(); ISearch[] searches = getSearches(); IBookmark[] bookmarks = getBookmarks(); if ( entries.length == 1 && searches.length == 0 && bookmarks.length == 0 ) { renameEntry( entries[0] ); } else if ( searches.length == 1 && entries.length == 0 && bookmarks.length == 0 ) { renameSearch( searches[0] ); } else if ( bookmarks.length == 1 && entries.length == 0 && searches.length == 0 ) { renameBookmark( bookmarks[0] ); } } /** * {@inheritDoc} */ public boolean isEnabled() { try { IEntry[] entries = getEntries(); ISearch[] searches = getSearches(); IBookmark[] bookmarks = getBookmarks(); return entries.length + searches.length + bookmarks.length == 1; } catch ( Exception e ) { return false; } } /** * Gets the Entries * * @return * the Entries */ protected IEntry[] getEntries() { IEntry entry = null; if ( getSelectedEntries().length == 1 ) { entry = getSelectedEntries()[0]; } else if ( getSelectedSearchResults().length == 1 ) { entry = getSelectedSearchResults()[0].getEntry(); } else if ( getSelectedValues().length == 1 && getSelectedValues()[0].isRdnPart() ) { entry = getSelectedValues()[0].getAttribute().getEntry(); } if ( entry != null && !( entry instanceof RootDSE ) ) { return new IEntry[] { entry }; } else { return new IEntry[0]; } } /** * Renames an Entry. * * @param entry * the Entry to rename */ protected void renameEntry( final IEntry entry ) { RenameEntryDialog renameDialog = new RenameEntryDialog( getShell(), entry ); if ( renameDialog.open() == Dialog.OK ) { Rdn newRdn = renameDialog.getRdn(); if ( newRdn != null && !newRdn.equals( entry.getRdn() ) ) { new StudioBrowserJob( new RenameEntryRunnable( entry, newRdn, new SimulateRenameDialogImpl( getShell() ) ) ).execute(); } } } /** * Get the Searches. * * @return * the Searches */ protected ISearch[] getSearches() { if ( getSelectedSearches().length == 1 && !( getSelectedSearches()[0] instanceof IQuickSearch ) ) { return getSelectedSearches(); } else { return new ISearch[0]; } } /** * Renames a Search. * * @param search * the Search to rename */ protected void renameSearch( final ISearch search ) { IInputValidator validator = new IInputValidator() { public String isValid( String newName ) { if ( search.getName().equals( newName ) ) return null; else if ( search.getBrowserConnection().getSearchManager().getSearch( newName ) != null ) return Messages.getString( "RenameAction.ConnectionWithThisNameAlreadyExists" ); //$NON-NLS-1$ else return null; } }; InputDialog dialog = new InputDialog( getShell(), Messages.getString( "RenameAction.RenameSearchDialog" ), Messages.getString( "RenameAction.RenameSearchNewName" ), search.getName(), validator ); //$NON-NLS-1$ //$NON-NLS-2$ dialog.open(); String newName = dialog.getValue(); if ( newName != null ) { search.setName( newName ); } } /** * Get the Bookmarks * * @return * the Bookmarks */ protected IBookmark[] getBookmarks() { if ( getSelectedBookmarks().length == 1 ) { return getSelectedBookmarks(); } else { return new IBookmark[0]; } } /** * Renames a Bookmark * * @param bookmark * the Bookmark to rename */ protected void renameBookmark( final IBookmark bookmark ) { IInputValidator validator = new IInputValidator() { public String isValid( String newName ) { if ( bookmark.getName().equals( newName ) ) return null; else if ( bookmark.getBrowserConnection().getBookmarkManager().getBookmark( newName ) != null ) return Messages.getString( "RenameAction.BookmarkWithThisNameAlreadyExists" ); //$NON-NLS-1$ else return null; } }; InputDialog dialog = new InputDialog( getShell(), Messages.getString( "RenameAction.RenameBookmarkDialog" ), Messages.getString( "RenameAction.RenameBookmarkNewName" ), bookmark.getName(), validator ); //$NON-NLS-1$ //$NON-NLS-2$ dialog.open(); String newName = dialog.getValue(); if ( newName != null ) { bookmark.setName( newName ); } } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/actions/PropertiesAction.java
plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/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.ldapbrowser.common.actions; import org.apache.directory.studio.ldapbrowser.common.BrowserCommonConstants; import org.apache.directory.studio.ldapbrowser.core.model.IAttribute; import org.apache.directory.studio.connection.core.Utils; import org.eclipse.core.runtime.IAdaptable; import org.eclipse.jface.preference.PreferenceDialog; import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.osgi.util.NLS; import org.eclipse.ui.dialogs.PreferencesUtil; import org.eclipse.ui.texteditor.IWorkbenchActionDefinitionIds; /** * This Action opens the Property Dialog for a given object. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class PropertiesAction extends BrowserAction { /** * Creates a new instance of PropertiesAction. */ public PropertiesAction() { super(); } /** * {@inheritDoc} */ public String getText() { return Messages.getString( "PropertiesAction.Properties" ); //$NON-NLS-1$ } /** * {@inheritDoc} */ public ImageDescriptor getImageDescriptor() { return null; } /** * {@inheritDoc} */ public String getCommandId() { return IWorkbenchActionDefinitionIds.PROPERTIES; } /** * {@inheritDoc} */ public boolean isEnabled() { return getSelectedEntries().length + getSelectedSearchResults().length + getSelectedBookmarks().length + getSelectedSearches().length == 1 || getSelectedAttributes().length + getSelectedValues().length == 1 || ( getSelectedAttributeHierarchies().length == 1 && getSelectedAttributeHierarchies()[0].size() == 1 ); } /** * {@inheritDoc} */ public void run() { IAdaptable element = null; String pageId = null; String title = null; if ( getSelectedValues().length == 1 ) { element = ( IAdaptable ) getSelectedValues()[0]; pageId = BrowserCommonConstants.PROP_VALUE; title = getSelectedValues()[0].toString(); } else if ( getSelectedAttributes().length == 1 ) { element = ( IAdaptable ) getSelectedAttributes()[0]; pageId = BrowserCommonConstants.PROP_ATTRIBUTE; title = getSelectedAttributes()[0].toString(); } else if ( getSelectedAttributeHierarchies().length == 1 ) { IAttribute att = getSelectedAttributeHierarchies()[0].getAttribute(); element = att; pageId = BrowserCommonConstants.PROP_ATTRIBUTE; title = att.toString(); } else if ( getSelectedSearches().length == 1 ) { element = ( IAdaptable ) getSelectedSearches()[0]; pageId = BrowserCommonConstants.PROP_SEARCH; title = getSelectedSearches()[0].getName(); } else if ( getSelectedBookmarks().length == 1 ) { element = ( IAdaptable ) getSelectedBookmarks()[0]; pageId = BrowserCommonConstants.PROP_BOOKMARK; title = getSelectedBookmarks()[0].getName(); } else if ( getSelectedEntries().length == 1 ) { element = ( IAdaptable ) getSelectedEntries()[0]; pageId = BrowserCommonConstants.PROP_ENTRY; title = getSelectedEntries()[0].getDn().getName(); } else if ( getSelectedSearchResults().length == 1 ) { element = ( IAdaptable ) getSelectedSearchResults()[0]; pageId = BrowserCommonConstants.PROP_ENTRY; title = getSelectedSearchResults()[0].getDn().getName(); } if ( element != null ) { PreferenceDialog dialog = PreferencesUtil.createPropertyDialogOn( getShell(), element, pageId, null, null ); if ( dialog != null ) { title = Utils.shorten( title, 30 ); } dialog.getShell().setText( NLS.bind( Messages.getString( "PropertiesAction.PropertiesForX" ), title ) ); //$NON-NLS-1$ dialog.open(); } } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/actions/OpenQuickSearchAction.java
plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/actions/OpenQuickSearchAction.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.ldapbrowser.common.actions; import org.apache.directory.studio.connection.core.Utils; import org.apache.directory.studio.ldapbrowser.common.BrowserCommonActivator; import org.apache.directory.studio.ldapbrowser.common.BrowserCommonConstants; import org.apache.directory.studio.ldapbrowser.core.jobs.SearchRunnable; import org.apache.directory.studio.ldapbrowser.core.jobs.StudioBrowserJob; 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.IQuickSearch; import org.apache.directory.studio.ldapbrowser.core.model.ISearch; import org.apache.directory.studio.ldapbrowser.core.model.impl.QuickSearch; import org.eclipse.jface.preference.PreferenceDialog; import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.osgi.util.NLS; import org.eclipse.ui.dialogs.PreferencesUtil; /** * This class implements the Open Quick Seach Action. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class OpenQuickSearchAction extends BrowserAction { /** * {@inheritDoc} */ public void run() { IBrowserConnection browserConnection = getBrowserConnection(); if ( browserConnection != null ) { // Getting the current quick search IQuickSearch quickSearch = browserConnection.getQuickSearch(); // Creating a new quick search with the currently selected entry // if there's no current quick search or quick search isn't selected if ( ( quickSearch == null ) || !isQuickSearchSelected() ) { // Setting a default search base on Root DSE IEntry searchBase = browserConnection.getRootDSE(); // Getting the selected entry IEntry selectedEntry = getSelectedEntry(); if ( selectedEntry != null ) { // Setting the selected entry as search base searchBase = selectedEntry; } // Creating a new quick search quickSearch = new QuickSearch( searchBase, browserConnection ); browserConnection.setQuickSearch( quickSearch ); } // Creating and opening the dialog PreferenceDialog dialog = PreferencesUtil.createPropertyDialogOn( getShell(), quickSearch, BrowserCommonConstants.PROP_SEARCH, null, null ); dialog.getShell().setText( NLS.bind( Messages.getString( "PropertiesAction.PropertiesForX" ), //$NON-NLS-1$ Utils.shorten( quickSearch.getName(), 30 ) ) ); if ( dialog.open() == PreferenceDialog.OK ) { // Performing the quick search if it has not been performed before // (ie. the quick search was not modified at in the dialog) if ( quickSearch.getSearchResults() == null ) { new StudioBrowserJob( new SearchRunnable( new ISearch[] { quickSearch } ) ).execute(); } } } } /** * {@inheritDoc} */ public String getText() { return Messages.getString( "OpenQuickSearchAction.OpenQuickSearch" ); //$NON-NLS-1$ } /** * {@inheritDoc} */ public ImageDescriptor getImageDescriptor() { return BrowserCommonActivator.getDefault().getImageDescriptor( BrowserCommonConstants.IMG_QUICKSEARCH ); } /** * {@inheritDoc} */ public String getCommandId() { return null; } /** * {@inheritDoc} */ public boolean isEnabled() { return getBrowserConnection() != null; } /** * Gets the browser connection. * * @return the browser connection */ private IBrowserConnection getBrowserConnection() { if ( getInput() instanceof IBrowserConnection ) { return ( IBrowserConnection ) getInput(); } else if ( getSelectedSearchResults().length > 0 ) { return getSelectedSearchResults()[0].getEntry().getBrowserConnection(); } else if ( getSelectedEntries().length > 0 ) { return getSelectedEntries()[0].getBrowserConnection(); } else if ( getSelectedSearches().length > 0 ) { return getSelectedSearches()[0].getBrowserConnection(); } return null; } /** * Gets the selected entry. * * @return the selected entry */ private IEntry getSelectedEntry() { if ( getSelectedEntries().length == 1 ) { return getSelectedEntries()[0]; } return null; } /** * Indicates if quick search is currently selected object. * * @return <code>true</code> if quick search is the currently selected object, * <code>false</code> if not. */ private boolean isQuickSearchSelected() { if ( getSelectedSearches().length == 1 ) { return getSelectedSearches()[0] instanceof IQuickSearch; } 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/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/actions/UpAction.java
plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/actions/UpAction.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.ldapbrowser.common.actions; import org.apache.directory.studio.ldapbrowser.common.BrowserCommonActivator; import org.apache.directory.studio.ldapbrowser.common.BrowserCommonConstants; import org.apache.directory.studio.ldapbrowser.common.widgets.browser.BrowserEntryPage; import org.apache.directory.studio.ldapbrowser.common.widgets.browser.BrowserSearchResultPage; import org.apache.directory.studio.ldapbrowser.core.model.IBookmark; import org.apache.directory.studio.ldapbrowser.core.model.IEntry; import org.apache.directory.studio.ldapbrowser.core.model.ISearch; import org.apache.directory.studio.ldapbrowser.core.model.ISearchResult; import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.jface.viewers.ITreeContentProvider; import org.eclipse.jface.viewers.StructuredSelection; import org.eclipse.jface.viewers.TreeViewer; /** * This class implements the Up Action. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class UpAction extends BrowserAction { protected TreeViewer viewer; /** * Creates a new instance of UpAction. * * @param viewer * the attached TreeViewer */ public UpAction( TreeViewer viewer ) { super(); this.viewer = viewer; } /** * {@inheritDoc} */ public String getText() { return Messages.getString( "UpAction.Up" ); //$NON-NLS-1$ } /** * {@inheritDoc} */ public ImageDescriptor getImageDescriptor() { return BrowserCommonActivator.getDefault().getImageDescriptor( BrowserCommonConstants.IMG_PARENT ); } /** * {@inheritDoc} */ public String getCommandId() { return BrowserCommonConstants.CMD_OPEN_SEARCH_RESULT; } /** * {@inheritDoc} */ public void run() { IEntry[] entries = getSelectedEntries(); ISearch[] searches = getSelectedSearches(); ISearchResult[] searchResults = getSelectedSearchResults(); IBookmark[] bookmarks = getSelectedBookmarks(); BrowserEntryPage[] browserEntryPages = getSelectedBrowserEntryPages(); BrowserSearchResultPage[] browserSearchResultPages = getSelectedBrowserSearchResultPages(); Object selection = null; if ( entries.length > 0 ) { selection = entries[0]; } else if ( searches.length > 0 ) { selection = searches[0]; } else if ( searchResults.length > 0 ) { selection = searchResults[0]; } else if ( bookmarks.length > 0 ) { selection = bookmarks[0]; } else if ( browserEntryPages.length > 0 ) { selection = browserEntryPages[0]; } else if ( browserSearchResultPages.length > 0 ) { selection = browserSearchResultPages[0]; } if ( selection != null ) { ITreeContentProvider contentProvider = ( ITreeContentProvider ) viewer.getContentProvider(); Object newSelection = contentProvider.getParent( selection ); viewer.reveal( newSelection ); viewer.setSelection( new StructuredSelection( newSelection ), true ); } } /** * {@inheritDoc} */ public boolean isEnabled() { IEntry[] entries = getSelectedEntries(); ISearch[] searches = getSelectedSearches(); ISearchResult[] searchResults = getSelectedSearchResults(); IBookmark[] bookmarks = getSelectedBookmarks(); BrowserEntryPage[] browserEntryPages = getSelectedBrowserEntryPages(); BrowserSearchResultPage[] browserSearchResultPages = getSelectedBrowserSearchResultPages(); return entries.length > 0 || searches.length > 0 || searchResults.length > 0 || bookmarks.length > 0 || browserEntryPages.length > 0 || browserSearchResultPages.length > 0; } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/actions/RefreshAction.java
plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/actions/RefreshAction.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.ldapbrowser.common.actions; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import org.apache.directory.studio.ldapbrowser.common.BrowserCommonActivator; import org.apache.directory.studio.ldapbrowser.common.BrowserCommonConstants; import org.apache.directory.studio.ldapbrowser.core.jobs.InitializeAttributesRunnable; import org.apache.directory.studio.ldapbrowser.core.jobs.InitializeChildrenRunnable; import org.apache.directory.studio.ldapbrowser.core.jobs.SearchRunnable; import org.apache.directory.studio.ldapbrowser.core.jobs.StudioBrowserJob; import org.apache.directory.studio.ldapbrowser.core.model.IBookmark; import org.apache.directory.studio.ldapbrowser.core.model.IContinuation; import org.apache.directory.studio.ldapbrowser.core.model.IEntry; import org.apache.directory.studio.ldapbrowser.core.model.ISearch; import org.apache.directory.studio.ldapbrowser.core.model.ISearchResult; import org.apache.directory.studio.ldapbrowser.core.model.IContinuation.State; import org.eclipse.jface.resource.ImageDescriptor; /** * This Action refreshes the selected item. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class RefreshAction extends BrowserAction { /** * Creates a new instance of RefreshAction. */ public RefreshAction() { super(); } /** * {@inheritDoc} */ public String getText() { List<IEntry> entries = getEntries(); ISearch[] searches = getSearches(); IEntry entryInput = getEntryInput(); ISearch searchInput = getSearchInput(); if ( entries.size() > 0 && searches.length == 0 && entryInput == null && searchInput == null ) { return entries.size() == 1 ? Messages.getString( "RefreshAction.ReloadEntry" ) : Messages.getString( "RefreshAction.ReloadEntries" ); //$NON-NLS-1$ //$NON-NLS-2$ } else if ( searches.length > 0 && entries.size() == 0 && entryInput == null && searchInput == null ) { boolean searchAgain = true; for ( int i = 0; i < searches.length; i++ ) { if ( searches[i].getSearchResults() == null ) { searchAgain = false; break; } } if ( searchAgain ) { return Messages.getString( "RefreshAction.SearchAgain" ); //$NON-NLS-1$ } else { return searches.length == 1 ? Messages.getString( "RefreshAction.PerformSearch" ) : Messages.getString( "RefreshAction.PerformSearches" ); //$NON-NLS-1$ //$NON-NLS-2$ } } else if ( entryInput != null && searches.length == 0 && entries.size() == 0 && searchInput == null ) { return Messages.getString( "RefreshAction.RelaodAttributes" ); //$NON-NLS-1$ } else if ( searchInput != null && searches.length == 0 && entryInput == null ) { return searchInput.getSearchResults() == null ? Messages.getString( "RefreshAction.PerformSearch" ) : Messages.getString( "RefreshAction.SearchAgain" ); //$NON-NLS-1$ //$NON-NLS-2$ } else { return Messages.getString( "RefreshAction.Refresh" ); //$NON-NLS-1$ } } /** * {@inheritDoc} */ public ImageDescriptor getImageDescriptor() { return BrowserCommonActivator.getDefault().getImageDescriptor( BrowserCommonConstants.IMG_REFRESH ); } /** * {@inheritDoc} */ public String getCommandId() { return "org.eclipse.ui.file.refresh"; //$NON-NLS-1$ } /** * {@inheritDoc} */ public void run() { List<IEntry> entries = getEntries(); ISearch[] searches = getSearches(); IEntry entryInput = getEntryInput(); ISearch searchInput = getSearchInput(); if ( entries.size() > 0 ) { for ( IEntry entry : entries ) { if ( entry instanceof IContinuation ) { IContinuation continuation = ( IContinuation ) entry; if ( continuation.getState() != State.RESOLVED ) { continuation.resolve(); } } } InitializeChildrenRunnable initializeChildrenRunnable = new InitializeChildrenRunnable( true, entries .toArray( new IEntry[0] ) ); new StudioBrowserJob( initializeChildrenRunnable ).execute(); } if ( searches.length > 0 ) { for ( ISearch search : searches ) { search.setSearchResults( null ); if ( search instanceof IContinuation ) { IContinuation continuation = ( IContinuation ) search; if ( continuation.getState() != State.RESOLVED ) { continuation.resolve(); } } } new StudioBrowserJob( new SearchRunnable( searches ) ).execute(); } if ( entryInput != null ) { // the entry input is usually a cloned entry, lookup the real entry from connection IEntry entry = entryInput.getBrowserConnection().getEntryFromCache( entryInput.getDn() ); new StudioBrowserJob( new InitializeAttributesRunnable( entry ) ).execute(); } if ( searchInput != null ) { // the search input is usually a cloned search, lookup the real search from connection ISearch search = searchInput.getBrowserConnection().getSearchManager().getSearch( searchInput.getName() ); search.setSearchResults( null ); new StudioBrowserJob( new SearchRunnable( new ISearch[] { search } ) ).execute(); } } /** * {@inheritDoc} */ public boolean isEnabled() { List<IEntry> entries = getEntries(); ISearch[] searches = getSearches(); IEntry entryInput = getEntryInput(); ISearch searchInput = getSearchInput(); return entries.size() > 0 || searches.length > 0 || entryInput != null || searchInput != null; } /** * Gets the Entries * * @return * the entries */ protected List<IEntry> getEntries() { List<IEntry> entries = new ArrayList<IEntry>(); entries.addAll( Arrays.asList( getSelectedEntries() ) ); for ( ISearchResult searchResult : getSelectedSearchResults() ) { entries.add( searchResult.getEntry() ); } for ( IBookmark bookmark : getSelectedBookmarks() ) { entries.add( bookmark.getEntry() ); } return entries; } /** * Gets the Searches. * * @return * the Searches */ protected ISearch[] getSearches() { return getSelectedSearches(); } /** * Gets the Entry Input. * * @return * the Entry Input */ private IEntry getEntryInput() { if ( getInput() instanceof IEntry ) { return ( IEntry ) getInput(); } else { return null; } } /** * Gets the Search Input. * * @return * the Search Input */ private ISearch getSearchInput() { if ( getInput() instanceof ISearch ) { return ( ISearch ) getInput(); } else { 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/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/actions/DeleteAllAction.java
plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/actions/DeleteAllAction.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.ldapbrowser.common.actions; import java.util.Arrays; import java.util.Collection; import java.util.HashSet; import org.apache.directory.studio.ldapbrowser.common.BrowserCommonActivator; import org.apache.directory.studio.ldapbrowser.common.BrowserCommonConstants; import org.apache.directory.studio.ldapbrowser.common.widgets.browser.BrowserCategory; import org.apache.directory.studio.ldapbrowser.core.model.IBookmark; import org.apache.directory.studio.ldapbrowser.core.model.IEntry; import org.apache.directory.studio.ldapbrowser.core.model.ISearch; import org.eclipse.jface.resource.ImageDescriptor; /** * This Action deletes all the Searches or Bookmarks. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class DeleteAllAction extends DeleteAction { private static final Collection<IEntry> EMPTY_ENTRIES = new HashSet<IEntry>(); private static final ISearch[] EMPTY_SEARCHES = new ISearch[0]; private static final IBookmark[] EMPTY_BOOKMARKS = new IBookmark[0]; /** * Creates a new instance of DeleteAllAction. */ public DeleteAllAction() { } /** * {@inheritDoc} */ public void run() { super.run(); } /** * {@inheritDoc} */ public String getText() { if ( getSelectedEntries().length >= 1 ) { return Messages.getString( "DeleteAllAction.DeleteAllChildEntries" ); //$NON-NLS-1$ } else if ( ( getSelectedSearches().length >= 1 ) || ( ( getSelectedBrowserViewCategories().length == 1 ) && ( getSelectedBrowserViewCategories()[0] .getType() == BrowserCategory.TYPE_SEARCHES ) ) ) { return Messages.getString( "DeleteAllAction.DeleteAllSearches" ); //$NON-NLS-1$ } else if ( ( getSelectedBookmarks().length >= 1 ) || ( ( getSelectedBrowserViewCategories().length == 1 ) && ( getSelectedBrowserViewCategories()[0] .getType() == BrowserCategory.TYPE_BOOKMARKS ) ) ) { return Messages.getString( "DeleteAllAction.DeleteAllBookmarks" ); //$NON-NLS-1$ } else { return Messages.getString( "DeleteAllAction.DeleteAll" ); //$NON-NLS-1$ } } /** * {@inheritDoc} */ public ImageDescriptor getImageDescriptor() { return BrowserCommonActivator.getDefault().getImageDescriptor( BrowserCommonConstants.IMG_DELETE_ALL ); } /** * {@inheritDoc} */ public String getCommandId() { return null; } /** * {@inheritDoc} */ protected Collection<IEntry> getEntries() { if ( getSelectedEntries().length >= 1 ) { Collection<IEntry> values = new HashSet<IEntry>(); values.addAll( Arrays.asList( getSelectedEntries()[0].getChildren() ) ); return values; } else { return EMPTY_ENTRIES; } } /** * {@inheritDoc} */ protected ISearch[] getSearches() { if ( getSelectedSearches().length >= 1 ) { return getSelectedSearches()[0].getBrowserConnection().getSearchManager().getSearches().toArray( new ISearch[0] ); } else if ( ( getSelectedBrowserViewCategories().length == 1 ) && ( getSelectedBrowserViewCategories()[0].getType() == BrowserCategory.TYPE_SEARCHES ) ) { return getSelectedBrowserViewCategories()[0].getParent().getSearchManager().getSearches().toArray( new ISearch[0] ); } else { return EMPTY_SEARCHES; } } /** * {@inheritDoc} */ protected IBookmark[] getBookmarks() { if ( getSelectedBookmarks().length >= 1 ) { return getSelectedBookmarks()[0].getBrowserConnection().getBookmarkManager().getBookmarks(); } else if ( ( getSelectedBrowserViewCategories().length == 1 ) && ( getSelectedBrowserViewCategories()[0].getType() == BrowserCategory.TYPE_BOOKMARKS ) ) { return getSelectedBrowserViewCategories()[0].getParent().getBookmarkManager().getBookmarks(); } else { return EMPTY_BOOKMARKS; } } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/actions/Messages.java
plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/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.ldapbrowser.common.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/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/actions/ShowDecoratedValuesAction.java
plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/actions/ShowDecoratedValuesAction.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.ldapbrowser.common.actions; import org.apache.directory.studio.ldapbrowser.common.BrowserCommonActivator; import org.apache.directory.studio.ldapbrowser.common.BrowserCommonConstants; import org.eclipse.jface.action.Action; /** * This Action toggles the Show Decorated Values Preference. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class ShowDecoratedValuesAction extends Action { /** * Creates a new instance of ShowRawValuesAction. */ public ShowDecoratedValuesAction() { super( Messages.getString( "ShowDecoratedValuesAction.ShowDecoratedValues" ), AS_CHECK_BOX ); //$NON-NLS-1$ setToolTipText( getText() ); setEnabled( true ); super.setChecked( !BrowserCommonActivator.getDefault().getPreferenceStore().getBoolean( BrowserCommonConstants.PREFERENCE_SHOW_RAW_VALUES ) ); } /** * {@inheritDoc} */ public void run() { BrowserCommonActivator.getDefault().getPreferenceStore().setValue( BrowserCommonConstants.PREFERENCE_SHOW_RAW_VALUES, !super.isChecked() ); } /** * {@inheritDoc} */ public void setChecked( boolean checked ) { super.setChecked( checked ); } /** * {@inheritDoc} */ public boolean isChecked() { return super.isChecked(); } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/actions/FetchOperationalAttributesAction.java
plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/actions/FetchOperationalAttributesAction.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.ldapbrowser.common.actions; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import org.apache.directory.studio.ldapbrowser.core.jobs.InitializeAttributesRunnable; import org.apache.directory.studio.ldapbrowser.core.jobs.StudioBrowserJob; import org.apache.directory.studio.ldapbrowser.core.model.IBookmark; import org.apache.directory.studio.ldapbrowser.core.model.IEntry; import org.apache.directory.studio.ldapbrowser.core.model.ISearchResult; import org.eclipse.jface.action.Action; import org.eclipse.jface.resource.ImageDescriptor; /** * This Action toggles weather to fetch operational attributes for an entry or not. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class FetchOperationalAttributesAction extends BrowserAction { /** * Creates a new instance of FetchOperationalAttributesAction. */ public FetchOperationalAttributesAction() { } @Override public int getStyle() { return Action.AS_CHECK_BOX; } @Override public String getText() { return Messages.getString( "FetchOperationalAttributesAction.FetchOperationalAttributes" ); //$NON-NLS-1$ } @Override public ImageDescriptor getImageDescriptor() { return null; } @Override public String getCommandId() { return null; } @Override public boolean isEnabled() { List<IEntry> entries = getEntries(); return !entries.isEmpty() && !entries.iterator().next().getBrowserConnection().isFetchOperationalAttributes(); } @Override public boolean isChecked() { boolean checked = true; List<IEntry> entries = getEntries(); if ( entries.isEmpty() ) { checked = false; } else { for ( IEntry entry : entries ) { if ( !entry.isInitOperationalAttributes() ) { checked = false; } } } return checked; } @Override public void run() { IEntry[] entries = getEntries().toArray( new IEntry[0] ); boolean init = !isChecked(); for ( IEntry entry : entries ) { entry.setInitOperationalAttributes( init ); } new StudioBrowserJob( new InitializeAttributesRunnable( entries ) ).execute(); } /** * Gets the Entries * * @return * the entries */ protected List<IEntry> getEntries() { List<IEntry> entriesList = new ArrayList<IEntry>(); entriesList.addAll( Arrays.asList( getSelectedEntries() ) ); for ( ISearchResult sr : getSelectedSearchResults() ) { entriesList.add( sr.getEntry() ); } for ( IBookmark bm : getSelectedBookmarks() ) { entriesList.add( bm.getEntry() ); } if ( getInput() instanceof IEntry ) { // the entry input is usually a cloned entry, lookup the real entry from connection IEntry input = ( IEntry ) getInput(); IEntry entry = input.getBrowserConnection().getEntryFromCache( input.getDn() ); if ( entry != null ) { entriesList.add( entry ); } } return entriesList; } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/actions/FetchAliasesAction.java
plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/actions/FetchAliasesAction.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.ldapbrowser.common.actions; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import org.apache.directory.studio.connection.core.Connection.AliasDereferencingMethod; import org.apache.directory.studio.ldapbrowser.core.jobs.InitializeChildrenRunnable; import org.apache.directory.studio.ldapbrowser.core.jobs.StudioBrowserJob; import org.apache.directory.studio.ldapbrowser.core.model.IEntry; import org.eclipse.jface.action.Action; import org.eclipse.jface.resource.ImageDescriptor; /** * This Action toggles weather to fetch aliases for an entry or not. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class FetchAliasesAction extends BrowserAction { /** * Creates a new instance of FetchAliasesAction. */ public FetchAliasesAction() { } @Override public int getStyle() { return Action.AS_CHECK_BOX; } @Override public String getText() { return Messages.getString( "FetchOperationalAttributesAction.FetchAliases" ); //$NON-NLS-1$ } @Override public ImageDescriptor getImageDescriptor() { return null; } @Override public String getCommandId() { return null; } @Override public boolean isEnabled() { List<IEntry> entries = getEntries(); return !entries.isEmpty() && entries.iterator().next().getBrowserConnection().getAliasesDereferencingMethod() != AliasDereferencingMethod.NEVER; } @Override public boolean isChecked() { boolean checked = true; List<IEntry> entries = getEntries(); if ( entries.isEmpty() ) { checked = false; } else { for ( IEntry entry : entries ) { if ( !entry.isFetchAliases() ) { checked = false; } } } return checked; } @Override public void run() { IEntry[] entries = getEntries().toArray( new IEntry[0] ); boolean init = !isChecked(); for ( IEntry entry : entries ) { entry.setFetchAliases( init ); } new StudioBrowserJob( new InitializeChildrenRunnable( true, entries ) ).execute(); } /** * Gets the Entries * * @return * the entries */ protected List<IEntry> getEntries() { List<IEntry> entriesList = new ArrayList<IEntry>(); entriesList.addAll( Arrays.asList( getSelectedEntries() ) ); return entriesList; } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/actions/CopyAction.java
plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/actions/CopyAction.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.ldapbrowser.common.actions; import java.util.Arrays; import java.util.LinkedHashSet; import org.apache.directory.studio.ldapbrowser.common.actions.proxy.BrowserActionProxy; import org.apache.directory.studio.ldapbrowser.common.dnd.EntryTransfer; import org.apache.directory.studio.ldapbrowser.common.dnd.SearchTransfer; import org.apache.directory.studio.ldapbrowser.common.dnd.ValuesTransfer; import org.apache.directory.studio.ldapbrowser.core.BrowserCoreConstants; import org.apache.directory.studio.ldapbrowser.core.model.AttributeHierarchy; import org.apache.directory.studio.ldapbrowser.core.model.IAttribute; import org.apache.directory.studio.ldapbrowser.core.model.IBookmark; import org.apache.directory.studio.ldapbrowser.core.model.IEntry; import org.apache.directory.studio.ldapbrowser.core.model.ISearch; import org.apache.directory.studio.ldapbrowser.core.model.ISearchResult; import org.apache.directory.studio.ldapbrowser.core.model.IValue; import org.apache.directory.studio.ldifparser.LdifUtils; import org.apache.directory.studio.valueeditors.IValueEditor; import org.apache.directory.studio.valueeditors.ValueEditorManager; import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.swt.dnd.Clipboard; import org.eclipse.swt.dnd.TextTransfer; import org.eclipse.swt.dnd.Transfer; import org.eclipse.swt.widgets.Display; import org.eclipse.ui.ISharedImages; import org.eclipse.ui.PlatformUI; import org.eclipse.ui.texteditor.IWorkbenchActionDefinitionIds; /** * This class implements the Copy Action * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class CopyAction extends BrowserAction { private BrowserActionProxy pasteActionProxy; private ValueEditorManager valueEditorManager; /** * Creates a new instance of CopyAction. * * @param pasteActionProxy * the associated Paste Action */ public CopyAction( BrowserActionProxy pasteActionProxy ) { super(); this.pasteActionProxy = pasteActionProxy; } /** * Creates a new instance of CopyAction. * * @param pasteActionProxy * the associated Paste Action */ public CopyAction( BrowserActionProxy pasteActionProxy, ValueEditorManager valueEditorManager ) { super(); this.pasteActionProxy = pasteActionProxy; this.valueEditorManager = valueEditorManager; } /** * {@inheritDoc} */ public String getText() { // entry/searchresult/bookmark IEntry[] entries = getEntries(); if ( entries != null ) { return entries.length > 1 ? Messages.getString( "CopyAction.CopyEntriesDNs" ) : Messages.getString( "CopyAction.CopyEntryDN" ); //$NON-NLS-1$ //$NON-NLS-2$ } // searches ISearch[] searches = getSearches(); if ( searches != null ) { return searches.length > 1 ? Messages.getString( "CopyAction.CopySearches" ) : Messages.getString( "CopyAction.CopySearch" ); //$NON-NLS-1$ //$NON-NLS-2$ } // values IValue[] values = getValues(); if ( values != null ) { return values.length > 1 ? Messages.getString( "CopyAction.CopyValues" ) : Messages.getString( "CopyAction.CopyValue" ); //$NON-NLS-1$ //$NON-NLS-2$ } return Messages.getString( "CopyAction.Copy" ); //$NON-NLS-1$ } /** * {@inheritDoc} */ public ImageDescriptor getImageDescriptor() { return PlatformUI.getWorkbench().getSharedImages().getImageDescriptor( ISharedImages.IMG_TOOL_COPY ); } /** * {@inheritDoc} */ public String getCommandId() { return IWorkbenchActionDefinitionIds.COPY; } /** * {@inheritDoc} */ public void run() { IEntry[] entries = getEntries(); ISearch[] searches = getSearches(); IValue[] values = getValues(); String[] stringProperties = getSelectedProperties(); // entry/searchresult/bookmark if ( entries != null ) { StringBuffer text = new StringBuffer(); for ( int i = 0; i < entries.length; i++ ) { text.append( entries[i].getDn().getName() ); if ( i + 1 < entries.length ) { text.append( BrowserCoreConstants.LINE_SEPARATOR ); } } copyToClipboard( new Object[] { entries, text.toString() }, new Transfer[] { EntryTransfer.getInstance(), TextTransfer.getInstance() } ); } // searches if ( searches != null ) { copyToClipboard( new Object[] { searches }, new Transfer[] { SearchTransfer.getInstance() } ); } // values else if ( values != null ) { StringBuffer text = new StringBuffer(); for ( int i = 0; i < values.length; i++ ) { IValue value = values[i]; if ( valueEditorManager != null ) { IValueEditor ve = valueEditorManager.getCurrentValueEditor( value ); String displayValue = ve.getDisplayValue( value ); text.append( displayValue ); } else if ( values[i].isString() ) { text.append( values[i].getStringValue() ); } else if ( values[i].isBinary() ) { text.append( LdifUtils.base64encode( values[i].getBinaryValue() ) ); } if ( i + 1 < values.length ) { text.append( BrowserCoreConstants.LINE_SEPARATOR ); } } copyToClipboard( new Object[] { values, text.toString() }, new Transfer[] { ValuesTransfer.getInstance(), TextTransfer.getInstance() } ); } // string properties else if ( stringProperties != null && stringProperties.length > 0 ) { StringBuffer text = new StringBuffer(); for ( int i = 0; i < stringProperties.length; i++ ) { text.append( stringProperties[i] ); if ( i + 1 < stringProperties.length ) { text.append( BrowserCoreConstants.LINE_SEPARATOR ); } } copyToClipboard( new Object[] { text.toString() }, new Transfer[] { TextTransfer.getInstance() } ); } // update paste action if ( this.pasteActionProxy != null ) { this.pasteActionProxy.updateAction(); } } /** * Copies data to Clipboard * * @param data * the data to be set in the clipboard * @param dataTypes * the transfer agents that will convert the data to its platform specific format; * each entry in the data array must have a corresponding dataType */ public static void copyToClipboard( Object[] data, Transfer[] dataTypes ) { Clipboard clipboard = null; try { clipboard = new Clipboard( Display.getCurrent() ); try { clipboard.setContents( data, dataTypes ); } catch ( IllegalArgumentException e ) { // Nothing to do. // Preventing an error to be shown in the case of the RootDSE being copied // See DIRSTUDIO-773 (IllegalArgumentException thrown when copying the RootDSE) // https://issues.apache.org/jira/browse/DIRSTUDIO-773 } } finally { if ( clipboard != null ) clipboard.dispose(); } } /** * {@inheritDoc} */ public boolean isEnabled() { // entry/searchresult/bookmark if ( getEntries() != null ) { return true; } // searches if ( getSearches() != null ) { return true; } // values else if ( getValues() != null ) { return true; } // string properties else if ( getSelectedProperties() != null && getSelectedProperties().length > 0 ) { return true; } else { return false; } } /** * Get the Entries * * @return * the Entries */ private IEntry[] getEntries() { if ( getSelectedConnections().length + getSelectedSearches().length + getSelectedAttributeHierarchies().length + getSelectedAttributes().length + getSelectedValues().length == 0 && getSelectedEntries().length + getSelectedSearchResults().length + getSelectedBookmarks().length > 0 ) { LinkedHashSet<IEntry> entriesSet = new LinkedHashSet<IEntry>(); for ( IEntry entry : getSelectedEntries() ) { entriesSet.add( entry ); } for ( ISearchResult searchResult : getSelectedSearchResults() ) { entriesSet.add( searchResult.getEntry() ); } for ( IBookmark bookmark : getSelectedBookmarks() ) { entriesSet.add( bookmark.getEntry() ); } return entriesSet.toArray( new IEntry[entriesSet.size()] ); } else { return null; } } /** * Get the Searches * * @return * the Searches */ private ISearch[] getSearches() { if ( getSelectedConnections().length + getSelectedEntries().length + getSelectedSearchResults().length + getSelectedBookmarks().length + getSelectedAttributeHierarchies().length + getSelectedAttributes().length + getSelectedValues().length == 0 && getSelectedSearches().length > 0 ) { LinkedHashSet<ISearch> searchesSet = new LinkedHashSet<ISearch>(); for ( ISearch search : getSelectedSearches() ) { searchesSet.add( search ); } return searchesSet.toArray( new ISearch[searchesSet.size()] ); } else { return null; } } /** * Get the Values * * @return * the Values */ private IValue[] getValues() { if ( getSelectedConnections().length + getSelectedBookmarks().length + getSelectedEntries().length + getSelectedSearches().length == 0 && getSelectedAttributeHierarchies().length + getSelectedAttributes().length + getSelectedValues().length > 0 ) { LinkedHashSet<IValue> valuesSet = new LinkedHashSet<IValue>(); for ( AttributeHierarchy ah : getSelectedAttributeHierarchies() ) { for ( IAttribute attribute : ah.getAttributes() ) { valuesSet.addAll( Arrays.asList( attribute.getValues() ) ); } } for ( IAttribute attribute : getSelectedAttributes() ) { valuesSet.addAll( Arrays.asList( attribute.getValues() ) ); } for ( IValue value : getSelectedValues() ) { valuesSet.add( value ); } return valuesSet.toArray( new IValue[valuesSet.size()] ); } else { 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/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/actions/SelectAllAction.java
plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/actions/SelectAllAction.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.ldapbrowser.common.actions; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import org.apache.directory.studio.connection.core.ConnectionManager; import org.apache.directory.studio.ldapbrowser.core.model.IAttribute; import org.apache.directory.studio.ldapbrowser.core.model.IEntry; import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.jface.viewers.StructuredSelection; import org.eclipse.jface.viewers.Viewer; import org.eclipse.ui.texteditor.IWorkbenchActionDefinitionIds; /** * This class implements the Select All Action. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class SelectAllAction extends BrowserAction { private Viewer viewer; /** * Creates a new instance of SelectAllAction. * * @param viewer * the attached viewer */ public SelectAllAction( Viewer viewer ) { this.viewer = viewer; } /** * {@inheritDoc} */ public String getText() { return Messages.getString( "SelectAllAction.SelectAll" ); //$NON-NLS-1$ } /** * {@inheritDoc} */ public ImageDescriptor getImageDescriptor() { return null; } /** * {@inheritDoc} */ public String getCommandId() { return IWorkbenchActionDefinitionIds.SELECT_ALL; } /** * {@inheritDoc} */ public boolean isEnabled() { return true; } /** * {@inheritDoc} */ public void run() { if ( getInput() instanceof IEntry ) { List selectionList = new ArrayList(); IAttribute[] attributes = ( ( IEntry ) getInput() ).getAttributes(); if ( attributes != null ) { selectionList.addAll( Arrays.asList( attributes ) ); for ( int i = 0; i < attributes.length; i++ ) { selectionList.addAll( Arrays.asList( attributes[i].getValues() ) ); } } StructuredSelection selection = new StructuredSelection( selectionList ); this.viewer.setSelection( selection ); } else if ( getInput() instanceof ConnectionManager ) { StructuredSelection selection = new StructuredSelection( ( ( ConnectionManager ) getInput() ) .getConnections() ); this.viewer.setSelection( selection ); } else if ( getSelectedConnections().length > 0 && viewer.getInput() instanceof ConnectionManager ) { StructuredSelection selection = new StructuredSelection( ( ( ConnectionManager ) viewer.getInput() ) .getConnections() ); this.viewer.setSelection( selection ); } } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/actions/FetchSubentriesAction.java
plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/actions/FetchSubentriesAction.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.ldapbrowser.common.actions; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import org.apache.directory.studio.ldapbrowser.core.jobs.InitializeChildrenRunnable; import org.apache.directory.studio.ldapbrowser.core.jobs.StudioBrowserJob; import org.apache.directory.studio.ldapbrowser.core.model.IEntry; import org.eclipse.jface.action.Action; import org.eclipse.jface.resource.ImageDescriptor; /** * This Action toggles weather to fetch subentries for an entry or not. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class FetchSubentriesAction extends BrowserAction { /** * Creates a new instance of FetchSubentriesAction. */ public FetchSubentriesAction() { } @Override public int getStyle() { return Action.AS_CHECK_BOX; } @Override public String getText() { return Messages.getString( "FetchOperationalAttributesAction.FetchSubentries" ); //$NON-NLS-1$ } @Override public ImageDescriptor getImageDescriptor() { return null; } @Override public String getCommandId() { return null; } @Override public boolean isEnabled() { List<IEntry> entries = getEntries(); return !entries.isEmpty() && !entries.iterator().next().getBrowserConnection().isFetchSubentries(); } @Override public boolean isChecked() { boolean checked = true; List<IEntry> entries = getEntries(); if ( entries.isEmpty() ) { checked = false; } else { for ( IEntry entry : entries ) { if ( !entry.isFetchSubentries() ) { checked = false; } } } return checked; } @Override public void run() { IEntry[] entries = getEntries().toArray( new IEntry[0] ); boolean init = !isChecked(); for ( IEntry entry : entries ) { entry.setFetchSubentries( init ); } new StudioBrowserJob( new InitializeChildrenRunnable( true, entries ) ).execute(); } /** * Gets the Entries * * @return * the entries */ protected List<IEntry> getEntries() { List<IEntry> entriesList = new ArrayList<IEntry>(); entriesList.addAll( Arrays.asList( getSelectedEntries() ) ); return entriesList; } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/actions/NewValueAction.java
plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/actions/NewValueAction.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.ldapbrowser.common.actions; import org.apache.directory.studio.ldapbrowser.common.BrowserCommonActivator; import org.apache.directory.studio.ldapbrowser.common.BrowserCommonConstants; import org.apache.directory.studio.ldapbrowser.core.model.IAttribute; import org.eclipse.jface.resource.ImageDescriptor; /** * This Action adds a new Value to an Attribute. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class NewValueAction extends BrowserAction { /** * Creates a new instance of NewValueAction. */ public NewValueAction() { super(); } /** * {@inheritDoc} */ public void dispose() { super.dispose(); } /** * {@inheritDoc} */ public void run() { IAttribute attribute = null; if ( getSelectedValues().length == 1 ) { attribute = getSelectedValues()[0].getAttribute(); } else if ( getSelectedAttributes().length == 1 ) { attribute = getSelectedAttributes()[0]; } else if ( getSelectedAttributeHierarchies().length == 1 ) { attribute = getSelectedAttributeHierarchies()[0].getAttribute(); } attribute.addEmptyValue(); } /** * {@inheritDoc} */ public String getText() { return Messages.getString( "NewValueAction.NewValue" ); //$NON-NLS-1$ } /** * {@inheritDoc} */ public ImageDescriptor getImageDescriptor() { return BrowserCommonActivator.getDefault().getImageDescriptor( BrowserCommonConstants.IMG_VALUE_ADD ); } /** * {@inheritDoc} */ public String getCommandId() { return BrowserCommonConstants.CMD_ADD_VALUE; } /** * {@inheritDoc} */ public boolean isEnabled() { return ( getSelectedSearchResults().length == 0 && getSelectedAttributes().length == 0 && getSelectedValues().length == 1 ) || ( getSelectedSearchResults().length == 0 && getSelectedValues().length == 0 && getSelectedAttributes().length == 1 ) || ( getSelectedSearchResults().length == 1 && getSelectedValues().length == 0 && getSelectedAttributes().length == 0 && getSelectedAttributeHierarchies().length == 1 ); } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/actions/DeleteAllValuesAction.java
plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/actions/DeleteAllValuesAction.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.ldapbrowser.common.actions; import java.util.Arrays; import java.util.Collection; import java.util.HashSet; import org.apache.directory.studio.ldapbrowser.common.BrowserCommonActivator; import org.apache.directory.studio.ldapbrowser.common.BrowserCommonConstants; import org.apache.directory.studio.ldapbrowser.core.model.IValue; import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.osgi.util.NLS; /** * This Action deletes all the values of an Attribute (a whole Attribute). * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class DeleteAllValuesAction extends DeleteAction { private static final Collection<IValue> EMPTY_VALUES = new HashSet<IValue>(); /** * Creates a new instance of DeleteAllValuesAction. */ public DeleteAllValuesAction() { } /** * {@inheritDoc} */ public void run() { super.run(); } /** * {@inheritDoc} */ public String getText() { if ( getSelectedValues().length == 1 ) { return NLS .bind( Messages.getString( "DeleteAllValuesAction.DeleteAttributeX" ), getSelectedValues()[0].getAttribute().getDescription() ); //$NON-NLS-1$ } else { return Messages.getString( "DeleteAllValuesAction.DeleteAttribute" ); //$NON-NLS-1$ } } /** * {@inheritDoc} */ public ImageDescriptor getImageDescriptor() { return BrowserCommonActivator.getDefault().getImageDescriptor( BrowserCommonConstants.IMG_DELETE_ALL ); } /** * {@inheritDoc} */ public String getCommandId() { return null; } /** * {@inheritDoc} */ public boolean isEnabled() { return super.isEnabled(); } /** * {@inheritDoc} */ protected Collection<IValue> getValues() { if ( getSelectedAttributes().length == 0 && getSelectedValues().length == 1 && getSelectedValues()[0].getAttribute().getValueSize() > 1 ) { Collection<IValue> values = new HashSet<IValue>(); values.addAll( Arrays.asList( getSelectedValues()[0].getAttribute().getValues() ) ); return values; } else { return EMPTY_VALUES; } } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/actions/UnfilterChildrenAction.java
plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/actions/UnfilterChildrenAction.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.ldapbrowser.common.actions; import org.apache.directory.studio.ldapbrowser.common.BrowserCommonActivator; import org.apache.directory.studio.ldapbrowser.common.BrowserCommonConstants; import org.apache.directory.studio.ldapbrowser.core.jobs.InitializeChildrenRunnable; import org.apache.directory.studio.ldapbrowser.core.jobs.StudioBrowserJob; import org.apache.directory.studio.ldapbrowser.core.model.IEntry; import org.eclipse.jface.resource.ImageDescriptor; /** * This action removes the children filter from the currently selected entry. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class UnfilterChildrenAction extends BrowserAction { /** * Creates a new instance of UnfilterChildrenAction. */ public UnfilterChildrenAction() { super(); } /** * {@inheritDoc} */ public void run() { if ( getSelectedEntries().length == 1 ) { IEntry entry = getSelectedEntries()[0]; entry.setChildrenFilter( null ); new StudioBrowserJob( new InitializeChildrenRunnable( true, entry ) ).execute(); } } /** * {@inheritDoc} */ public String getText() { return Messages.getString( "UnfilterChildrenAction.RemoveChildrenFilter" ); //$NON-NLS-1$ } /** * {@inheritDoc} */ public ImageDescriptor getImageDescriptor() { return BrowserCommonActivator.getDefault().getImageDescriptor( BrowserCommonConstants.IMG_UNFILTER_DIT ); } /** * {@inheritDoc} */ public String getCommandId() { return null; } /** * {@inheritDoc} */ public boolean isEnabled() { return getSelectedSearches().length + getSelectedSearchResults().length + getSelectedBookmarks().length == 0 && getSelectedEntries().length == 1 && getSelectedEntries()[0].getChildrenFilter() != 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/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/actions/FilterChildrenAction.java
plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/actions/FilterChildrenAction.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.ldapbrowser.common.actions; import org.apache.directory.studio.ldapbrowser.common.BrowserCommonActivator; import org.apache.directory.studio.ldapbrowser.common.BrowserCommonConstants; import org.apache.directory.studio.ldapbrowser.common.dialogs.FilterWidgetDialog; import org.apache.directory.studio.ldapbrowser.core.jobs.InitializeChildrenRunnable; import org.apache.directory.studio.ldapbrowser.core.jobs.StudioBrowserJob; import org.apache.directory.studio.ldapbrowser.core.model.IEntry; import org.eclipse.jface.dialogs.Dialog; import org.eclipse.jface.resource.ImageDescriptor; /** * This action opens the Filter Children Dialog and sets the children filter to the * currently selected entry. It is useful when browsing the DIT and entries with * many child nodes. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class FilterChildrenAction extends BrowserAction { /** * Creates a new instance of FilterChildrenAction. */ public FilterChildrenAction() { super(); } /** * {@inheritDoc} */ public void run() { if ( getSelectedEntries().length == 1 ) { IEntry entry = getSelectedEntries()[0]; FilterWidgetDialog dialog = new FilterWidgetDialog( getShell(), Messages .getString( "FilterChildrenAction.FilterChildren" ), //$NON-NLS-1$ entry.getChildrenFilter(), entry.getBrowserConnection() ); if ( dialog.open() == Dialog.OK ) { String newFilter = dialog.getFilter(); if ( newFilter == null || "".equals( newFilter.trim() ) ) //$NON-NLS-1$ { entry.setChildrenFilter( null ); } else { entry.setChildrenFilter( newFilter.trim() ); } new StudioBrowserJob( new InitializeChildrenRunnable( true, entry ) ).execute(); } } } /** * {@inheritDoc} */ public String getText() { return Messages.getString( "FilterChildrenAction.FilterChildrenLabel" ); //$NON-NLS-1$ } /** * {@inheritDoc} */ public ImageDescriptor getImageDescriptor() { return BrowserCommonActivator.getDefault().getImageDescriptor( BrowserCommonConstants.IMG_FILTER_DIT ); } /** * {@inheritDoc} */ public String getCommandId() { return null; } /** * {@inheritDoc} */ public boolean isEnabled() { return getSelectedSearches().length + getSelectedSearchResults().length + getSelectedBookmarks().length == 0 && getSelectedEntries().length == 1 && ( getSelectedEntries()[0].hasChildren() || getSelectedEntries()[0].getChildrenFilter() != 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/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/actions/BrowserAction.java
plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/actions/BrowserAction.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.ldapbrowser.common.actions; import org.apache.directory.studio.connection.ui.actions.StudioAction; import org.apache.directory.studio.ldapbrowser.common.widgets.browser.BrowserCategory; import org.apache.directory.studio.ldapbrowser.common.widgets.browser.BrowserEntryPage; import org.apache.directory.studio.ldapbrowser.common.widgets.browser.BrowserSearchResultPage; import org.apache.directory.studio.ldapbrowser.core.model.AttributeHierarchy; import org.apache.directory.studio.ldapbrowser.core.model.IAttribute; import org.apache.directory.studio.ldapbrowser.core.model.IBookmark; import org.apache.directory.studio.ldapbrowser.core.model.IEntry; import org.apache.directory.studio.ldapbrowser.core.model.ISearch; import org.apache.directory.studio.ldapbrowser.core.model.ISearchResult; import org.apache.directory.studio.ldapbrowser.core.model.IValue; import org.apache.directory.studio.ldifparser.model.LdifFile; import org.apache.directory.studio.ldifparser.model.LdifPart; import org.apache.directory.studio.ldifparser.model.container.LdifContainer; import org.eclipse.jface.action.IAction; import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.jface.viewers.ISelection; import org.eclipse.swt.widgets.Shell; import org.eclipse.ui.IWorkbenchWindow; import org.eclipse.ui.IWorkbenchWindowActionDelegate; import org.eclipse.ui.PlatformUI; /** * This abstract class must be extended by each Action related to the Browser. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public abstract class BrowserAction extends StudioAction implements IWorkbenchWindowActionDelegate { /** The selected Browser View Categories */ private BrowserCategory[] selectedBrowserViewCategories; /** The selected Entries */ private IEntry[] selectedEntries; /** The selected Browser Entry Pages */ private BrowserEntryPage[] selectedBrowserEntryPages; /** The selected Searches */ private ISearch[] selectedSearches; /** The selected Search Results */ private ISearchResult[] selectedSearchResults; /** The selected Browser Search Result Pages */ private BrowserSearchResultPage[] selectedBrowserSearchResultPages; /** The selected Bookmarks */ private IBookmark[] selectedBookmarks; /** The selected Attributes */ private IAttribute[] selectedAttributes; /** The selected Attribute Hierarchies */ private AttributeHierarchy[] selectedAttributeHierarchies; /** The selected Values */ private IValue[] selectedValues; /** The selectec LDIF Model */ private LdifFile selectedLdifModel; /** The selected LDIF Containers */ private LdifContainer[] selectedLdifContainers; /** The selected LDIF Parts */ private LdifPart[] selectedLdifParts; /** The selected properties. */ protected String[] selectedProperties; /** The input */ private Object input; /** * Creates a new instance of BrowserAction. */ protected BrowserAction() { init(); } /** * {@inheritDoc} */ public void init( IWorkbenchWindow window ) { init(); } /** * {@inheritDoc} */ public void run( IAction action ) { this.run(); } /** * {@inheritDoc} */ public void selectionChanged( IAction action, ISelection selection ) { setSelectedBrowserViewCategories( BrowserSelectionUtils.getBrowserViewCategories( selection ) ); setSelectedEntries( BrowserSelectionUtils.getEntries( selection ) ); setSelectedBrowserEntryPages( BrowserSelectionUtils.getBrowserEntryPages( selection ) ); setSelectedSearchResults( BrowserSelectionUtils.getSearchResults( selection ) ); setSelectedBrowserSearchResultPages( BrowserSelectionUtils.getBrowserSearchResultPages( selection ) ); setSelectedBookmarks( BrowserSelectionUtils.getBookmarks( selection ) ); setSelectedSearches( BrowserSelectionUtils.getSearches( selection ) ); setSelectedAttributes( BrowserSelectionUtils.getAttributes( selection ) ); setSelectedAttributeHierarchies( BrowserSelectionUtils.getAttributeHierarchie( selection ) ); setSelectedValues( BrowserSelectionUtils.getValues( selection ) ); action.setEnabled( this.isEnabled() ); action.setText( this.getText() ); action.setToolTipText( this.getText() ); } /** * Returns the text for this action. * <p> * This method is associated with the <code>TEXT</code> property; * property change events are reported when its value changes. * </p> * * @return the text, or <code>null</code> if none */ public abstract String getText(); /** * Returns the image for this action as an image descriptor. * <p> * This method is associated with the <code>IMAGE</code> property; * property change events are reported when its value changes. * </p> * * @return the image, or <code>null</code> if this action has no image */ public abstract ImageDescriptor getImageDescriptor(); /** * Returns the command identifier. * * @return the command identifier */ public abstract String getCommandId(); /** * Returns whether this action is enabled. * <p> * This method is associated with the <code>ENABLED</code> property; * property change events are reported when its value changes. * </p> * * @return <code>true</code> if enabled, and * <code>false</code> if disabled */ public abstract boolean isEnabled(); /** * Runs this action. * Each action implementation must define the steps needed to carry out this action. * The default implementation of this method in <code>Action</code> * does nothing. */ public abstract void run(); /** * Initializes this action */ private void init() { selectedBrowserViewCategories = new BrowserCategory[0]; selectedEntries = new IEntry[0]; selectedBrowserEntryPages = new BrowserEntryPage[0]; selectedSearches = new ISearch[0]; selectedSearchResults = new ISearchResult[0]; selectedBrowserSearchResultPages = new BrowserSearchResultPage[0]; selectedBookmarks = new IBookmark[0]; selectedAttributes = new IAttribute[0]; selectedAttributeHierarchies = new AttributeHierarchy[0]; selectedValues = new IValue[0]; selectedLdifModel = null; selectedLdifContainers = new LdifContainer[0]; selectedLdifParts = new LdifPart[0]; selectedProperties = new String[0]; input = null; } /** * {@inheritDoc} */ public void dispose() { selectedBrowserViewCategories = new BrowserCategory[0]; selectedEntries = new IEntry[0]; selectedBrowserEntryPages = new BrowserEntryPage[0]; selectedSearches = new ISearch[0]; selectedSearchResults = new ISearchResult[0]; selectedBrowserSearchResultPages = new BrowserSearchResultPage[0]; selectedBookmarks = new IBookmark[0]; selectedAttributes = new IAttribute[0]; selectedAttributeHierarchies = new AttributeHierarchy[0]; selectedValues = new IValue[0]; selectedLdifModel = null; selectedLdifContainers = new LdifContainer[0]; selectedLdifParts = new LdifPart[0]; selectedProperties = new String[0]; input = null; } /** * Returns the current active shell * * @return the current active shell */ protected Shell getShell() { return PlatformUI.getWorkbench().getDisplay().getActiveShell(); } /** * Gets the selected Attributes. * * @return the selected attributes */ public IAttribute[] getSelectedAttributes() { return selectedAttributes; } /** * Sets the selected Attributes. * * @param selectedAttributes the selected attributes to set */ public void setSelectedAttributes( IAttribute[] selectedAttributes ) { this.selectedAttributes = selectedAttributes; } /** * Gets the selected Bookmarks. * * @return the selected Bookmarks */ public IBookmark[] getSelectedBookmarks() { return selectedBookmarks; } /** * Sets the selected Bookmarks. * * @param selectedBookmarks the selected Bookmarks to set */ public void setSelectedBookmarks( IBookmark[] selectedBookmarks ) { this.selectedBookmarks = selectedBookmarks; } /** * Gets the selected Browser View categories. * * @return the selected Browser View categories */ public BrowserCategory[] getSelectedBrowserViewCategories() { return selectedBrowserViewCategories; } /** * Sets the selected Browser View categories. * * @param selectedBrowserViewCategories the selected Browser View categories to set */ public void setSelectedBrowserViewCategories( BrowserCategory[] selectedBrowserViewCategories ) { this.selectedBrowserViewCategories = selectedBrowserViewCategories; } /** * Get the selected Entries. * * @return the selected entries */ public IEntry[] getSelectedEntries() { return selectedEntries; } /** * Sets the selected Entries. * * @param selectedEntries the selected Entries to set */ public void setSelectedEntries( IEntry[] selectedEntries ) { this.selectedEntries = selectedEntries; } /** * Gets the selected Searches. * * @return the selected Searches */ public ISearch[] getSelectedSearches() { return selectedSearches; } /** * Sets the selected Searches. * * @param selectedSearches the selected Searches to set */ public void setSelectedSearches( ISearch[] selectedSearches ) { this.selectedSearches = selectedSearches; } /** * Gets the selected Search Results. * * @return the selected Search Results */ public ISearchResult[] getSelectedSearchResults() { return selectedSearchResults; } /** * Sets the selected Search Results. * * @param selectedSearchResults the selected Search Results to set */ public void setSelectedSearchResults( ISearchResult[] selectedSearchResults ) { this.selectedSearchResults = selectedSearchResults; } /** * Gets the selected Values. * * @return the selected Values */ public IValue[] getSelectedValues() { return selectedValues; } /** * Sets the selected Values. * * @param selectedValues the selected values to set */ public void setSelectedValues( IValue[] selectedValues ) { this.selectedValues = selectedValues; } /** * Gets the input. * * @return the input */ public Object getInput() { return input; } /** * Sets the input. * * @param input the input to set */ public void setInput( Object input ) { this.input = input; } /** * Gets the selected LDIF Containers. * * @return the selected LDIF Containers */ public LdifContainer[] getSelectedLdifContainers() { return selectedLdifContainers; } /** * Sets the selected LDIF Containers. * * @param selectedLdifContainers the selected LDIF Containers to set */ public void setSelectedLdifContainers( LdifContainer[] selectedLdifContainers ) { this.selectedLdifContainers = selectedLdifContainers; } /** * Gets the selected LDIF Model. * * @return the selected LDIF Model */ public LdifFile getSelectedLdifModel() { return selectedLdifModel; } /** * Sets the selected LDIF Model. * * @param selectedLdifModel the selected LDIF Model to set */ public void setSelectedLdifModel( LdifFile selectedLdifModel ) { this.selectedLdifModel = selectedLdifModel; } /** * Gets the selected LDIF Parts. * * @return the selected LDIF Parts */ public LdifPart[] getSelectedLdifParts() { return selectedLdifParts; } /** * Sets the selected LDIF Parts. * * @param selectedLdifParts the selected LDIF Parts to set */ public void setSelectedLdifParts( LdifPart[] selectedLdifParts ) { this.selectedLdifParts = selectedLdifParts; } /** * Gets the selected Browser Entry Pages. * * @return the selected Browser Entru Pages */ public BrowserEntryPage[] getSelectedBrowserEntryPages() { return selectedBrowserEntryPages; } /** * Sets the selected Browser Entry Pages. * * @param selectedBrowserEntryPages the selected Browser Entry Pages to set */ public void setSelectedBrowserEntryPages( BrowserEntryPage[] selectedBrowserEntryPages ) { this.selectedBrowserEntryPages = selectedBrowserEntryPages; } /** * Gets the selected Browser Search Result Pages. * * @return the selected Browser Search Result Pages */ public BrowserSearchResultPage[] getSelectedBrowserSearchResultPages() { return selectedBrowserSearchResultPages; } /** * Sets the selected Browser Search Result Pages. * * @param selectedBrowserSearchResultPages the selected Browser Search result Pages to set */ public void setSelectedBrowserSearchResultPages( BrowserSearchResultPage[] selectedBrowserSearchResultPages ) { this.selectedBrowserSearchResultPages = selectedBrowserSearchResultPages; } /** * Gets the selected Attribute Hierarchies. * * @return the selected Attribute Hierarchies */ public AttributeHierarchy[] getSelectedAttributeHierarchies() { return selectedAttributeHierarchies; } /** * Sets the selected Attribute Hierarchies. * * @param ahs the selected Attribute Hierarchies to set */ public void setSelectedAttributeHierarchies( AttributeHierarchy[] ahs ) { this.selectedAttributeHierarchies = ahs; } /** * Gets the selected properties. * * @return the selected properties */ public String[] getSelectedProperties() { return selectedProperties; } /** * Sets the selected properties. * * @param selectedProperties the selected properties */ public void setSelectedProperties( String[] selectedProperties ) { this.selectedProperties = selectedProperties; } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/actions/BrowserSelectionUtils.java
plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/actions/BrowserSelectionUtils.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.ldapbrowser.common.actions; import java.util.ArrayList; import java.util.Arrays; import java.util.Comparator; import java.util.Iterator; import java.util.LinkedHashSet; import java.util.List; import java.util.Set; import org.apache.directory.api.ldap.model.message.SearchScope; import org.apache.directory.api.ldap.model.schema.AttributeType; import org.apache.directory.studio.connection.core.Connection; import org.apache.directory.studio.connection.ui.actions.SelectionUtils; import org.apache.directory.studio.ldapbrowser.common.widgets.browser.BrowserCategory; import org.apache.directory.studio.ldapbrowser.common.widgets.browser.BrowserEntryPage; import org.apache.directory.studio.ldapbrowser.common.widgets.browser.BrowserSearchResultPage; import org.apache.directory.studio.ldapbrowser.core.BrowserCorePlugin; import org.apache.directory.studio.ldapbrowser.core.model.AttributeHierarchy; import org.apache.directory.studio.ldapbrowser.core.model.IAttribute; import org.apache.directory.studio.ldapbrowser.core.model.IBookmark; 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.ISearch; import org.apache.directory.studio.ldapbrowser.core.model.ISearchResult; import org.apache.directory.studio.ldapbrowser.core.model.IValue; import org.apache.directory.studio.ldapbrowser.core.model.impl.Search; import org.apache.directory.studio.ldapbrowser.core.utils.LdapFilterUtils; import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jface.viewers.StructuredSelection; /** * The SelectionUtils are used to extract specific beans from the current * selection (org.eclipse.jface.viewers.ISelection). * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public abstract class BrowserSelectionUtils extends SelectionUtils { /** * This method creates a prototype search from the given selection. * * Depended on the selected element it determines the best connection, * search base and filter: * <ul> * <li>ISearch: all parameters are copied to the prototype search (clone) * <li>IEntry or ISearchResult or IBookmark: Dn is used as search base * <li>IEntry: children filter is used as filter * <li>IAttribute or IValue: the entry's Dn is used as search base, * the filter is built using the name-value-pairs (query by example). * </ul> * * @param selection the current selection * @return a prototype search */ public static ISearch getExampleSearch( ISelection selection ) { ISearch exampleSearch = new Search(); String oldName = exampleSearch.getSearchParameter().getName(); exampleSearch.getSearchParameter().setName( null ); exampleSearch.setScope( SearchScope.SUBTREE ); if ( ( selection instanceof StructuredSelection ) && !selection.isEmpty() ) { Object[] objects = ( ( IStructuredSelection ) selection ).toArray(); Comparator<Object> comparator = new Comparator<Object>() { public int compare( Object o1, Object o2 ) { if ( ( o1 instanceof IValue ) && !( o2 instanceof IValue ) ) { return -1; } else if ( !( o1 instanceof IValue ) && ( o2 instanceof IValue ) ) { return 1; } else if ( ( o1 instanceof IAttribute ) && !( o2 instanceof IAttribute ) ) { return -1; } else if ( !( o1 instanceof IAttribute ) && ( o2 instanceof IAttribute ) ) { return 1; } else if ( ( o1 instanceof AttributeHierarchy ) && !( o2 instanceof AttributeHierarchy ) ) { return -1; } else if ( !( o1 instanceof AttributeHierarchy ) && ( o2 instanceof AttributeHierarchy ) ) { return 1; } return 0; } }; Arrays.sort( objects, comparator ); Object obj = objects[0]; if ( obj instanceof ISearch ) { ISearch search = ( ISearch ) obj; exampleSearch = ( ISearch ) search.clone(); exampleSearch.setName( null ); } else if ( obj instanceof IEntry ) { IEntry entry = ( IEntry ) obj; exampleSearch.setBrowserConnection( entry.getBrowserConnection() ); exampleSearch.setSearchBase( entry.getDn() ); exampleSearch.setFilter( entry.getChildrenFilter() ); } else if ( obj instanceof ISearchResult ) { ISearchResult searchResult = ( ISearchResult ) obj; exampleSearch.setBrowserConnection( searchResult.getEntry().getBrowserConnection() ); exampleSearch.setSearchBase( searchResult.getEntry().getDn() ); } else if ( obj instanceof IBookmark ) { IBookmark bookmark = ( IBookmark ) obj; exampleSearch.setBrowserConnection( bookmark.getBrowserConnection() ); exampleSearch.setSearchBase( bookmark.getDn() ); } else if ( obj instanceof AttributeHierarchy || obj instanceof IAttribute || obj instanceof IValue ) { IEntry entry = null; Set<String> filterSet = new LinkedHashSet<String>(); for ( int i = 0; i < objects.length; i++ ) { Object object = objects[i]; if ( object instanceof AttributeHierarchy ) { AttributeHierarchy ah = ( AttributeHierarchy ) object; for ( IAttribute attribute : ah ) { entry = attribute.getEntry(); IValue[] values = attribute.getValues(); for ( int v = 0; v < values.length; v++ ) { filterSet.add( LdapFilterUtils.getFilter( values[v] ) ); } } } else if ( object instanceof IAttribute ) { IAttribute attribute = ( IAttribute ) object; entry = attribute.getEntry(); IValue[] values = attribute.getValues(); for ( int v = 0; v < values.length; v++ ) { filterSet.add( LdapFilterUtils.getFilter( values[v] ) ); } } else if ( object instanceof IValue ) { IValue value = ( IValue ) object; entry = value.getAttribute().getEntry(); filterSet.add( LdapFilterUtils.getFilter( value ) ); } } exampleSearch.setBrowserConnection( entry.getBrowserConnection() ); exampleSearch.setSearchBase( entry.getDn() ); StringBuffer filter = new StringBuffer(); if ( filterSet.size() > 1 ) { filter.append( "(&" ); //$NON-NLS-1$ for ( Iterator<String> filterIterator = filterSet.iterator(); filterIterator.hasNext(); ) { filter.append( filterIterator.next() ); } filter.append( ")" ); //$NON-NLS-1$ } else if ( filterSet.size() == 1 ) { filter.append( filterSet.toArray()[0] ); } else { filter.append( ISearch.FILTER_TRUE ); } exampleSearch.setFilter( filter.toString() ); } else if ( obj instanceof Connection ) { IBrowserConnection connection = BrowserCorePlugin.getDefault().getConnectionManager() .getBrowserConnection( ( Connection ) obj ); exampleSearch.setBrowserConnection( connection ); if ( connection.getRootDSE().getChildrenCount() > 0 ) { exampleSearch.setSearchBase( connection.getRootDSE().getChildren()[0].getDn() ); } else { exampleSearch.setSearchBase( connection.getRootDSE().getDn() ); } } else if ( obj instanceof IBrowserConnection ) { IBrowserConnection connection = ( IBrowserConnection ) obj; exampleSearch.setBrowserConnection( connection ); if ( connection.getRootDSE().getChildrenCount() > 0 ) { exampleSearch.setSearchBase( connection.getRootDSE().getChildren()[0].getDn() ); } else { exampleSearch.setSearchBase( connection.getRootDSE().getDn() ); } } else if ( obj instanceof BrowserCategory ) { BrowserCategory cat = ( BrowserCategory ) obj; exampleSearch.setBrowserConnection( cat.getParent() ); if ( cat.getParent().getRootDSE().getChildrenCount() > 0 ) { exampleSearch.setSearchBase( cat.getParent().getRootDSE().getChildren()[0].getDn() ); } else { exampleSearch.setSearchBase( cat.getParent().getRootDSE().getDn() ); } } } exampleSearch.getSearchParameter().setName( oldName ); return exampleSearch; } /** * Gets the BrowserCategory beans contained in the given selection. * * @param selection the selection * @return an array with BrowserCategory beans, may be empty. */ public static BrowserCategory[] getBrowserViewCategories( ISelection selection ) { List<Object> list = getTypes( selection, BrowserCategory.class ); return list.toArray( new BrowserCategory[list.size()] ); } /** * Gets the IValue beans contained in the given selection. * * @param selection the selection * @return an array with IValue beans, may be empty. */ public static IValue[] getValues( ISelection selection ) { List<Object> list = getTypes( selection, IValue.class ); return list.toArray( new IValue[list.size()] ); } /** * Gets the IAttribute beans contained in the given selection. * * @param selection the selection * @return an array with IAttribute beans, may be empty. */ public static IAttribute[] getAttributes( ISelection selection ) { List<Object> list = getTypes( selection, IAttribute.class ); return list.toArray( new IAttribute[list.size()] ); } /** * Gets the AttributeHierarchy beans contained in the given selection. * * @param selection the selection * @return an array with AttributeHierarchy beans, may be empty. */ public static AttributeHierarchy[] getAttributeHierarchie( ISelection selection ) { List<Object> list = getTypes( selection, AttributeHierarchy.class ); return list.toArray( new AttributeHierarchy[list.size()] ); } /** * Gets the Strings contained in the given selection. * * @param selection the selection * @return an array with Strings, may be empty. */ public static String[] getProperties( ISelection selection ) { List<Object> list = getTypes( selection, String.class ); return list.toArray( new String[list.size()] ); } /** * Gets the AttributeTypeDescription beans contained in the given selection. * * @param selection the selection * @return an array with AttributeTypeDescription beans, may be empty. */ public static AttributeType[] getAttributeTypeDescription( ISelection selection ) { List<Object> list = getTypes( selection, AttributeType.class ); return list.toArray( new AttributeType[list.size()] ); } /** * Gets the IEntry beans contained in the given selection. * * @param selection the selection * @return an array with IEntry beans, may be empty. */ public static IEntry[] getEntries( ISelection selection ) { List<Object> list = getTypes( selection, IEntry.class ); return list.toArray( new IEntry[list.size()] ); } /** * Gets the IBookmark beans contained in the given selection. * * @param selection the selection * @return an array with IBookmark beans, may be empty. */ public static IBookmark[] getBookmarks( ISelection selection ) { List<Object> list = getTypes( selection, IBookmark.class ); return list.toArray( new IBookmark[list.size()] ); } /** * Gets the ISearchResult beans contained in the given selection. * * @param selection the selection * @return an array with ISearchResult beans, may be empty. */ public static ISearchResult[] getSearchResults( ISelection selection ) { List<Object> list = getTypes( selection, ISearchResult.class ); return list.toArray( new ISearchResult[list.size()] ); } /** * Gets all beans of the requested type contained in the given selection. * * @param selection the selection * @param type the requested type * @return a list containing beans of the requested type */ private static List<Object> getTypes( ISelection selection, Class<?> type ) { List<Object> list = new ArrayList<Object>(); if ( selection instanceof IStructuredSelection ) { IStructuredSelection structuredSelection = ( IStructuredSelection ) selection; for ( Object element : structuredSelection.toArray() ) { if ( type.isInstance( element ) ) { list.add( element ); } } } return list; } /** * Gets the ISearch beans contained in the given selection. * * @param selection the selection * @return an array with ISearch beans, may be empty. */ public static ISearch[] getSearches( ISelection selection ) { List<Object> list = getTypes( selection, ISearch.class ); return list.toArray( new ISearch[list.size()] ); } /** * Gets the BrowserEntryPage beans contained in the given selection. * * @param selection the selection * @return an array with BrowserEntryPage beans, may be empty. */ public static BrowserEntryPage[] getBrowserEntryPages( ISelection selection ) { List<Object> list = getTypes( selection, BrowserEntryPage.class ); return list.toArray( new BrowserEntryPage[list.size()] ); } /** * Gets the BrowserSearchResultPage beans contained in the given selection. * * @param selection the selection * @return an array with BrowserSearchResultPage beans, may be empty. */ public static BrowserSearchResultPage[] getBrowserSearchResultPages( ISelection selection ) { List<Object> list = getTypes( selection, BrowserSearchResultPage.class ); return list.toArray( new BrowserSearchResultPage[list.size()] ); } /** * Gets the objects contained in the given selection. * * @param selection the selection * @return an array with object, may be empty. */ public static Object[] getObjects( ISelection selection ) { List<Object> list = getTypes( selection, Object.class ); return list.toArray( new Object[list.size()] ); } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/actions/proxy/ActionHandlerManager.java
plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/actions/proxy/ActionHandlerManager.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.ldapbrowser.common.actions.proxy; /** * A ActionHandlerManager activates and deactives the action handlers. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public interface ActionHandlerManager { /** * Deactivates global action handlers. */ void deactivateGlobalActionHandlers(); /** * Activates global action handlers. */ void activateGlobalActionHandlers(); }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/actions/proxy/BrowserViewActionProxy.java
plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/actions/proxy/BrowserViewActionProxy.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.ldapbrowser.common.actions.proxy; import org.apache.directory.studio.ldapbrowser.common.actions.BrowserAction; import org.eclipse.jface.viewers.Viewer; /** * The BrowserViewActionProxy is a proxy for a real action. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class BrowserViewActionProxy extends BrowserActionProxy { /** * Creates a new instance of BrowserViewActionProxy. * * @param viewer the viewer * @param action the real action */ public BrowserViewActionProxy( Viewer viewer, BrowserAction action ) { super( viewer, action ); } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/actions/proxy/EntryEditorActionProxy.java
plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/actions/proxy/EntryEditorActionProxy.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.ldapbrowser.common.actions.proxy; import org.apache.directory.studio.ldapbrowser.common.actions.BrowserAction; import org.eclipse.jface.viewers.ISelectionChangedListener; import org.eclipse.jface.viewers.Viewer; /** * The EntryEditorActionProxy is a proxy for a real action. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class EntryEditorActionProxy extends BrowserActionProxy implements ISelectionChangedListener { /** * Creates a new instance of EntryEditorActionProxy. * * @param viewer the viewer * @param action the real action */ public EntryEditorActionProxy( Viewer viewer, BrowserAction action ) { super( viewer, action ); } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/actions/proxy/BrowserActionProxy.java
plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/actions/proxy/BrowserActionProxy.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.ldapbrowser.common.actions.proxy; import org.apache.directory.studio.connection.core.Connection; import org.apache.directory.studio.connection.core.ConnectionFolder; import org.apache.directory.studio.connection.core.event.ConnectionEventRegistry; import org.apache.directory.studio.connection.core.event.ConnectionUpdateListener; import org.apache.directory.studio.connection.ui.ConnectionUIPlugin; import org.apache.directory.studio.ldapbrowser.common.BrowserCommonActivator; import org.apache.directory.studio.ldapbrowser.common.actions.BrowserAction; import org.apache.directory.studio.ldapbrowser.common.actions.BrowserSelectionUtils; import org.apache.directory.studio.ldapbrowser.core.events.BookmarkUpdateEvent; import org.apache.directory.studio.ldapbrowser.core.events.BookmarkUpdateListener; import org.apache.directory.studio.ldapbrowser.core.events.EntryModificationEvent; import org.apache.directory.studio.ldapbrowser.core.events.EntryUpdateListener; import org.apache.directory.studio.ldapbrowser.core.events.EventRegistry; import org.apache.directory.studio.ldapbrowser.core.events.SearchUpdateEvent; import org.apache.directory.studio.ldapbrowser.core.events.SearchUpdateListener; import org.eclipse.jface.action.Action; import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.ISelectionChangedListener; import org.eclipse.jface.viewers.ISelectionProvider; import org.eclipse.jface.viewers.SelectionChangedEvent; import org.eclipse.jface.viewers.StructuredSelection; public abstract class BrowserActionProxy extends Action implements ISelectionChangedListener, EntryUpdateListener, SearchUpdateListener, BookmarkUpdateListener, ConnectionUpdateListener { /** The action */ protected BrowserAction action; protected ISelectionProvider selectionProvider; protected BrowserActionProxy( ISelectionProvider selectionProvider, BrowserAction action, int style ) { super( action.getText(), style ); this.selectionProvider = selectionProvider; this.action = action; super.setImageDescriptor( action.getImageDescriptor() ); super.setActionDefinitionId( action.getCommandId() ); selectionProvider.addSelectionChangedListener( this ); // PlatformUI.getWorkbench().getActiveWorkbenchWindow().getSelectionService().addSelectionListener(this); ConnectionEventRegistry.addConnectionUpdateListener( this, ConnectionUIPlugin.getDefault().getEventRunner() ); EventRegistry.addEntryUpdateListener( this, BrowserCommonActivator.getDefault().getEventRunner() ); EventRegistry.addSearchUpdateListener( this, BrowserCommonActivator.getDefault().getEventRunner() ); EventRegistry.addBookmarkUpdateListener( this, BrowserCommonActivator.getDefault().getEventRunner() ); updateAction(); } protected BrowserActionProxy( ISelectionProvider selectionProvider, BrowserAction action ) { this( selectionProvider, action, action.getStyle() ); } public void dispose() { ConnectionEventRegistry.removeConnectionUpdateListener( this ); EventRegistry.removeEntryUpdateListener( this ); EventRegistry.removeSearchUpdateListener( this ); EventRegistry.removeBookmarkUpdateListener( this ); selectionProvider.removeSelectionChangedListener( this ); // PlatformUI.getWorkbench().getActiveWorkbenchWindow().getSelectionService().removeSelectionListener(this); action.dispose(); action = null; } public boolean isDisposed() { return action == null; } public final void entryUpdated( EntryModificationEvent entryModificationEvent ) { if ( !isDisposed() ) { updateAction(); } } public void searchUpdated( SearchUpdateEvent searchUpdateEvent ) { if ( !isDisposed() ) { updateAction(); } } public void bookmarkUpdated( BookmarkUpdateEvent bookmarkUpdateEvent ) { if ( !isDisposed() ) { updateAction(); } } /** * @see org.apache.directory.studio.connection.core.event.ConnectionUpdateListener#connectionUpdated(org.apache.directory.studio.connection.core.Connection) */ public final void connectionUpdated( Connection connection ) { if ( !isDisposed() ) { updateAction(); } } /** * @see org.apache.directory.studio.connection.core.event.ConnectionUpdateListener#connectionAdded(org.apache.directory.studio.connection.core.Connection) */ public void connectionAdded( Connection connection ) { connectionUpdated( connection ); } /** * @see org.apache.directory.studio.connection.core.event.ConnectionUpdateListener#connectionRemoved(org.apache.directory.studio.connection.core.Connection) */ public void connectionRemoved( Connection connection ) { connectionUpdated( connection ); } /** * @see org.apache.directory.studio.connection.core.event.ConnectionUpdateListener#connectionOpened(org.apache.directory.studio.connection.core.Connection) */ public void connectionOpened( Connection connection ) { connectionUpdated( connection ); } /** * @see org.apache.directory.studio.connection.core.event.ConnectionUpdateListener#connectionClosed(org.apache.directory.studio.connection.core.Connection) */ public void connectionClosed( Connection connection ) { connectionUpdated( connection ); } /** * @see org.apache.directory.studio.connection.core.event.ConnectionUpdateListener#connectionFolderModified(org.apache.directory.studio.connection.core.ConnectionFolder) */ public void connectionFolderModified( ConnectionFolder connectionFolder ) { connectionUpdated( null ); } /** * @see org.apache.directory.studio.connection.core.event.ConnectionUpdateListener#connectionFolderAdded(org.apache.directory.studio.connection.core.ConnectionFolder) */ public void connectionFolderAdded( ConnectionFolder connectionFolder ) { connectionUpdated( null ); } /** * @see org.apache.directory.studio.connection.core.event.ConnectionUpdateListener#connectionFolderRemoved(org.apache.directory.studio.connection.core.ConnectionFolder) */ public void connectionFolderRemoved( ConnectionFolder connectionFolder ) { connectionUpdated( null ); } public void inputChanged( Object input ) { if ( !this.isDisposed() ) { action.setInput( input ); selectionChanged( new SelectionChangedEvent( selectionProvider, new StructuredSelection() ) ); // this.updateAction(); } } public void selectionChanged( SelectionChangedEvent event ) { if ( !isDisposed() ) { ISelection selection = event.getSelection(); action.setSelectedBrowserViewCategories( BrowserSelectionUtils.getBrowserViewCategories( selection ) ); action.setSelectedEntries( BrowserSelectionUtils.getEntries( selection ) ); action.setSelectedBrowserEntryPages( BrowserSelectionUtils.getBrowserEntryPages( selection ) ); action.setSelectedSearchResults( BrowserSelectionUtils.getSearchResults( selection ) ); action.setSelectedBrowserSearchResultPages( BrowserSelectionUtils.getBrowserSearchResultPages( selection ) ); action.setSelectedBookmarks( BrowserSelectionUtils.getBookmarks( selection ) ); action.setSelectedSearches( BrowserSelectionUtils.getSearches( selection ) ); action.setSelectedAttributes( BrowserSelectionUtils.getAttributes( selection ) ); action.setSelectedAttributeHierarchies( BrowserSelectionUtils.getAttributeHierarchie( selection ) ); action.setSelectedValues( BrowserSelectionUtils.getValues( selection ) ); action.setSelectedProperties( BrowserSelectionUtils.getProperties( selection ) ); updateAction(); } } public void updateAction() { if ( !isDisposed() ) { String text = action.getText(); setText( text ); setToolTipText( text ); setEnabled( action.isEnabled() ); setImageDescriptor( action.getImageDescriptor() ); setChecked( action.isChecked() ); } } public void run() { if ( !isDisposed() ) { action.run(); } } public BrowserAction getAction() { return action; } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/ListContentProposalProvider.java
plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/ListContentProposalProvider.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.ldapbrowser.common.widgets; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.List; import org.eclipse.jface.fieldassist.IContentProposal; import org.eclipse.jface.fieldassist.IContentProposalProvider; /** * ListContentProposalProvider is a class designed to map a dynamic list of * Strings to content proposals. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class ListContentProposalProvider implements IContentProposalProvider { /** The dynamic list of proposals */ private List<String> proposals; /** * Creates a new instance of ListContentProposalProvider. * * @param proposals the dynamic list of proposals */ public ListContentProposalProvider( List<String> proposals ) { setProposals( proposals ); } /** * Creates a new instance of ListContentProposalProvider. * * @param proposals the proposals */ public ListContentProposalProvider( String[] proposals ) { setProposals( new ArrayList<String>( Arrays.asList( proposals ) ) ); } /** * {@inheritDoc} */ public IContentProposal[] getProposals( String contents, int position ) { String string = contents.substring( 0, position ); Collections.sort( proposals ); List<IContentProposal> proposalList = new ArrayList<IContentProposal>(); for ( int k = 0; k < proposals.size(); k++ ) { final String proposal = proposals.get( k ); if ( proposal.toUpperCase().startsWith( string.toUpperCase() ) && !"".equals( string ) ) //$NON-NLS-1$ { IContentProposal p = new IContentProposal() { public String getContent() { return proposal; } public String getDescription() { return proposal; } public String getLabel() { return proposal; } public int getCursorPosition() { return proposal.length(); } }; proposalList.add( p ); } } return proposalList.toArray( new IContentProposal[proposalList.size()] ); } /** * Sets the possible strings. * * @param newProposals the possible strings */ public void setProposals( List<String> newProposals ) { if ( newProposals == null ) { this.proposals = new ArrayList<String>(); } else { this.proposals = new ArrayList<String>( newProposals ); } } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/ModWidget.java
plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/ModWidget.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.ldapbrowser.common.widgets; import java.util.ArrayList; import java.util.Arrays; import org.apache.directory.studio.common.ui.widgets.AbstractWidget; import org.apache.directory.studio.common.ui.widgets.BaseWidgetUtils; import org.apache.directory.studio.connection.ui.widgets.ExtendedContentAssistCommandAdapter; import org.apache.directory.studio.ldapbrowser.core.BrowserCoreConstants; import org.apache.directory.studio.ldapbrowser.core.model.schema.Schema; import org.apache.directory.studio.ldapbrowser.core.model.schema.SchemaUtils; import org.eclipse.jface.fieldassist.ComboContentAdapter; import org.eclipse.swt.SWT; import org.eclipse.swt.custom.ScrolledComposite; import org.eclipse.swt.events.ModifyEvent; import org.eclipse.swt.events.ModifyListener; import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Combo; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Group; import org.eclipse.swt.widgets.Text; /** * The ModWidget provides input elements to define an LDAP modify * operation. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class ModWidget extends AbstractWidget { /** The scrolled composite */ private ScrolledComposite scrolledComposite; /** The composite that contains the ModSpecs */ private Composite composite; /** The list of ModSpecs */ private ArrayList<ModSpec> modSpecList = new ArrayList<ModSpec>(); /** The list content proposal provider */ private ListContentProposalProvider listContentProposalProvider; /** The resulting LDIF */ private String ldif; // Listeners private ModifyListener modifyListener = new ModifyListener() { public void modifyText( ModifyEvent e ) { validate( true ); } }; /** * Creates a new instance of ModWidget. * * @param schema the schema with the possible attribute types */ public ModWidget( Schema schema ) { String[] attributeDescriptions = SchemaUtils.getNamesAsArray( schema.getAttributeTypeDescriptions() ); Arrays.sort( attributeDescriptions ); listContentProposalProvider = new ListContentProposalProvider( attributeDescriptions ); } /** * Disposes this widget. */ public void dispose() { } /** * Gets the ldif. * * @return the ldif */ public String getLdif() { return ldif; } /** * Creates the contents. * * @param parent the parent composite * * @return the created composite */ public Composite createContents( Composite parent ) { // Creating the scrolled composite containing all UI scrolledComposite = new ScrolledComposite( parent, SWT.H_SCROLL | SWT.V_SCROLL ); scrolledComposite.setLayout( new GridLayout() ); scrolledComposite.setExpandHorizontal( true ); scrolledComposite.setLayoutData( new GridData( SWT.FILL, SWT.FILL, true, true ) ); // Creating the composite composite = BaseWidgetUtils.createColumnContainer( scrolledComposite, 3, 1 ); composite.setLayoutData( new GridData( SWT.FILL, SWT.FILL, true, true ) ); scrolledComposite.setContent( composite ); addInitialModSpec(); validate( false ); return scrolledComposite; } /** * Validates the input elements. */ public void validate( boolean notifyListeners ) { for ( int i = 0; i < modSpecList.size(); i++ ) { ModSpec modSpec = ( ModSpec ) modSpecList.get( i ); if ( modSpecList.size() > 1 ) { modSpec.modDeleteButton.setEnabled( true ); } else { modSpec.modDeleteButton.setEnabled( false ); } for ( int k = 0; k < modSpec.valueLineList.size(); k++ ) { ValueLine valueLine = ( ValueLine ) modSpec.valueLineList.get( k ); if ( modSpec.valueLineList.size() > 1 ) { valueLine.valueDeleteButton.setEnabled( true ); } else { valueLine.valueDeleteButton.setEnabled( false ); } } } if ( notifyListeners ) { notifyListeners(); } } /** * Adds an initial modification spec. * */ private void addInitialModSpec() { addModSpec( 0 ); } /** * Adds a modification spec at the given index. * * @param index the index */ private void addModSpec( int index ) { // Getting the array of modification specs ModSpec[] modSpecs = ( ModSpec[] ) modSpecList.toArray( new ModSpec[modSpecList.size()] ); // Adding a new modification spec ModSpec newModSpec = createModSpec( true ); modSpecList.add( newModSpec ); if ( modSpecs.length > 0 ) { for ( int i = index; i < modSpecs.length; i++ ) { ModSpec modSpec = modSpecs[i]; // That's a trick to relocate the modification spec // beneath the newly created one modSpec.modGroup.setParent( scrolledComposite ); modSpec.modAddButton.setParent( scrolledComposite ); modSpec.modDeleteButton.setParent( scrolledComposite ); modSpec.modGroup.setParent( composite ); modSpec.modAddButton.setParent( composite ); modSpec.modDeleteButton.setParent( composite ); // Same trick to update the id in the list modSpecList.remove( modSpec ); modSpecList.add( modSpec ); } } composite.setSize( composite.computeSize( SWT.DEFAULT, SWT.DEFAULT ) ); } /** * Creates and returns a modification spec. * * @param addFirstValueLine if a first value line should added * @return the created modification spec */ private ModSpec createModSpec( boolean addFirstValueLine ) { ModSpec modSpec = new ModSpec(); modSpec.modGroup = BaseWidgetUtils.createGroup( composite, "", 1 ); //$NON-NLS-1$ modSpec.modGroup.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) ); Composite modSpecComposite = BaseWidgetUtils.createColumnContainer( modSpec.modGroup, 2, 1 ); modSpec.modType = BaseWidgetUtils.createReadonlyCombo( modSpecComposite, new String[] { "add", "replace", "delete" }, 0, 1 ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ modSpec.modType.setLayoutData( new GridData() ); modSpec.modType.addModifyListener( modifyListener ); // attribute combo with field decoration and content proposal modSpec.modAttributeCombo = BaseWidgetUtils.createCombo( modSpecComposite, new String[0], -1, 1 ); new ExtendedContentAssistCommandAdapter( modSpec.modAttributeCombo, new ComboContentAdapter(), listContentProposalProvider, null, null, true ); modSpec.modAttributeCombo.addModifyListener( modifyListener ); // add button with listener modSpec.modAddButton = new Button( composite, SWT.PUSH ); modSpec.modAddButton.setText( " + " ); //$NON-NLS-1$ modSpec.modAddButton.addSelectionListener( new SelectionAdapter() { public void widgetSelected( SelectionEvent e ) { int index = modSpecList.size(); for ( int i = 0; i < modSpecList.size(); i++ ) { ModSpec modSpec = modSpecList.get( i ); if ( modSpec.modAddButton == e.widget ) { index = i + 1; } } addModSpec( index ); validate( true ); } } ); // delete button with listener modSpec.modDeleteButton = new Button( composite, SWT.PUSH ); modSpec.modDeleteButton.setText( " \u2212 " ); //$NON-NLS-1$ modSpec.modDeleteButton.addSelectionListener( new SelectionAdapter() { public void widgetSelected( SelectionEvent e ) { int index = 0; for ( int i = 0; i < modSpecList.size(); i++ ) { ModSpec modSpec = modSpecList.get( i ); if ( modSpec.modDeleteButton == e.widget ) { index = i; } } deleteModSpec( index ); validate( true ); } } ); if ( addFirstValueLine ) { addValueLine( modSpec, 0, false ); } return modSpec; } /** * Delets a modification spec. * * @param index the index */ private void deleteModSpec( int index ) { ModSpec modSpec = modSpecList.remove( index ); if ( modSpec != null ) { modSpec.modGroup.dispose(); modSpec.modAddButton.dispose(); modSpec.modDeleteButton.dispose(); composite.setSize( composite.computeSize( SWT.DEFAULT, SWT.DEFAULT ) ); } } /** * Adds a value line to the given modification spec. * * @param modSpec the modification spec * @param index the index * @param boolean the flag to update the size */ private void addValueLine( ModSpec modSpec, int index, boolean updateSize ) { ValueLine[] valueLines = modSpec.valueLineList.toArray( new ValueLine[modSpec.valueLineList.size()] ); ValueLine newValueLine = createValueLine( modSpec ); modSpec.valueLineList.add( newValueLine ); if ( valueLines.length > 0 ) { for ( int i = index; i < valueLines.length; i++ ) { ValueLine valueLine = valueLines[i]; // That's a trick to relocate the value line // beneath the newly created one Composite parentComposite = valueLine.valueComposite.getParent(); valueLine.valueComposite.setParent( scrolledComposite ); valueLine.valueComposite.setParent( parentComposite ); // Same trick to update the id in the list modSpec.valueLineList.remove( valueLine ); modSpec.valueLineList.add( valueLine ); } } if ( updateSize ) { composite.setSize( composite.computeSize( SWT.DEFAULT, SWT.DEFAULT ) ); } } /** * Creates the value line. * * @param modSpec the modification spec * * @return the value line */ private ValueLine createValueLine( final ModSpec modSpec ) { final ValueLine valueLine = new ValueLine(); // text field valueLine.valueComposite = BaseWidgetUtils.createColumnContainer( modSpec.modGroup, 3, 1 ); valueLine.valueText = BaseWidgetUtils.createText( valueLine.valueComposite, "", 1 ); //$NON-NLS-1$ valueLine.valueText.addModifyListener( modifyListener ); // add button with listener valueLine.valueAddButton = new Button( valueLine.valueComposite, SWT.PUSH ); valueLine.valueAddButton.setText( " + " ); //$NON-NLS-1$ valueLine.valueAddButton.addSelectionListener( new SelectionAdapter() { public void widgetSelected( SelectionEvent e ) { int index = modSpec.valueLineList.size(); for ( int i = 0; i < modSpec.valueLineList.size(); i++ ) { ValueLine valueLine = modSpec.valueLineList.get( i ); if ( valueLine.valueAddButton == e.widget ) { index = i + 1; } } addValueLine( modSpec, index, true ); validate( true ); } } ); // delete button with listener valueLine.valueDeleteButton = new Button( valueLine.valueComposite, SWT.PUSH ); valueLine.valueDeleteButton.setText( " \u2212 " ); //$NON-NLS-1$ valueLine.valueDeleteButton.addSelectionListener( new SelectionAdapter() { public void widgetSelected( SelectionEvent e ) { int index = 0; for ( int i = 0; i < modSpec.valueLineList.size(); i++ ) { ValueLine valueLine = modSpec.valueLineList.get( i ); if ( valueLine.valueDeleteButton == e.widget ) { index = i; } } deleteValueLine( modSpec, index ); validate( true ); } } ); return valueLine; } /** * Delete value line. * * @param modSpec the mod spec * @param index the index */ private void deleteValueLine( ModSpec modSpec, int index ) { ValueLine valueLine = ( ValueLine ) modSpec.valueLineList.remove( index ); if ( valueLine != null ) { valueLine.valueComposite.dispose(); composite.setSize( composite.computeSize( SWT.DEFAULT, SWT.DEFAULT ) ); } } /** * Gets the LDIF fragment. * * @return the LDIF fragment */ public String getLdifFragment() { StringBuffer sb = new StringBuffer(); sb.append( "changetype: modify" ).append( BrowserCoreConstants.LINE_SEPARATOR ); //$NON-NLS-1$ ModSpec[] modSpecs = ( ModSpec[] ) modSpecList.toArray( new ModSpec[modSpecList.size()] ); if ( modSpecs.length > 0 ) { for ( int i = 0; i < modSpecs.length; i++ ) { ModSpec modSpec = modSpecs[i]; // get values String type = modSpec.modType.getText(); String attribute = modSpec.modAttributeCombo.getText(); String[] values = new String[modSpec.valueLineList.size()]; for ( int k = 0; k < values.length; k++ ) { values[k] = ( ( ValueLine ) modSpec.valueLineList.get( k ) ).valueText.getText(); } // build ldif sb.append( type ).append( ": " ).append( attribute ).append( BrowserCoreConstants.LINE_SEPARATOR ); //$NON-NLS-1$ for ( int k = 0; k < values.length; k++ ) { if ( values[k].length() > 0 ) { sb.append( attribute ).append( ": " ).append( values[k] ).append( //$NON-NLS-1$ BrowserCoreConstants.LINE_SEPARATOR ); } } sb.append( "-" ).append( BrowserCoreConstants.LINE_SEPARATOR ); //$NON-NLS-1$ // sb.append(BrowserCoreConstants.NEWLINE); } } return sb.toString(); } /** * The Class ModSpec is a wrapper for all input elements * of an modification. It contains a combo for the modify * operation, a combo for the attribute to modify, * value lines and + and - buttons to add and remove * other modifications. It looks like this: * <pre> * ---------------------------------- * | operation v | attribute type v |-------- * ------------------------ --------| + | - | * | value | + | - |-------- * ---------------------------------- * </pre> */ private class ModSpec { /** The mod group. */ private Group modGroup; /** The mod type. */ private Combo modType; /** The modification attribute. */ private Combo modAttributeCombo; /** The mod add button. */ private Button modAddButton; /** The mod delete button. */ private Button modDeleteButton; /** The value line list. */ private ArrayList<ValueLine> valueLineList = new ArrayList<ValueLine>();; } /** * The Class ValueLine is a wrapper for all input elements * of an value line. It contains an input field for the value * and + and - buttons to add and remove other value lines. * It looks like this: * <pre> * ------------------------------------- * | value | + | - | * ------------------------------------- * </pre> */ private class ValueLine { /** The value composite. */ private Composite valueComposite; /** The value text. */ private Text valueText; /** The value add button. */ private Button valueAddButton; /** The value delete button. */ private Button valueDeleteButton; } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/BinaryEncodingInput.java
plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/BinaryEncodingInput.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.ldapbrowser.common.widgets; import org.apache.directory.studio.ldapbrowser.core.BrowserCoreConstants; /** * The BinaryEncodingInput is an OptionInput with fixed options. * It is used to select the encoding of binary attributes. The default * value is always {@link BrowserCoreConstants#BINARYENCODING_IGNORE}. * The other options are always {@link BrowserCoreConstants#BINARYENCODING_IGNORE}, * {@link BrowserCoreConstants#BINARYENCODING_BASE64} and * {@link BrowserCoreConstants#BINARYENCODING_HEX}. No custom input is allowed. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class BinaryEncodingInput extends OptionsInput { /** * Creates a new instance of BinaryEncodingInput. * * @param initialRawValue the initial raw value * @param asGroup the asGroup flag */ public BinaryEncodingInput( String initialRawValue, boolean asGroup ) { super( Messages.getString( "BinaryEncodingInput.BinaryEncoding" ), getDefaultDisplayValue(), getDefaultRawValue(), getOtherDisplayValues(), //$NON-NLS-1$ getOtherRawValues(), initialRawValue, asGroup, false ); } /** * Gets the default display value, always "Ignore". * * @return the default display value */ private static String getDefaultDisplayValue() { return Messages.getString( "BinaryEncodingInput.Ignore" ); //$NON-NLS-1$ } /** * Gets the default raw value, always * {@link BrowserCoreConstants.BINARYENCODING_IGNORE}. * * @return the default raw value */ private static String getDefaultRawValue() { return Integer.toString( BrowserCoreConstants.BINARYENCODING_IGNORE ); } /** * Gets the other display values. * * @return the other display values */ private static String[] getOtherDisplayValues() { return new String[] { Messages.getString( "BinaryEncodingInput.Ignore" ), "BASE-64", "HEX" }; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ } /** * Gets the other raw values. * * @return the other raw values */ private static String[] getOtherRawValues() { return new String[] { Integer.toString( BrowserCoreConstants.BINARYENCODING_IGNORE ), Integer.toString( BrowserCoreConstants.BINARYENCODING_BASE64 ), Integer.toString( BrowserCoreConstants.BINARYENCODING_HEX ) }; } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/FileEncodingInput.java
plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/FileEncodingInput.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.ldapbrowser.common.widgets; import java.nio.charset.Charset; import org.apache.directory.studio.ldapbrowser.core.BrowserCoreConstants; /** * The FileEncodingInput is an OptionInput with fixed options. * It is used to select the file encoding. The default * value is always the platform's default encoding. * The other options are the values return from * {@link Charset#availableCharsets()}. No custom input is allowed. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class FileEncodingInput extends OptionsInput { /** * Creates a new instance of FileEncodingInput. * * @param initialRawValue the initial raw value * @param asGroup the asGroup flag */ public FileEncodingInput( String initialRawValue, boolean asGroup ) { super( Messages.getString( "FileEncodingInput.FileEncoding" ), getDefaultDisplayValue(), getDefaultRawValue(), getOtherDisplayValues(), //$NON-NLS-1$ getOtherRawValues(), initialRawValue, asGroup, false ); } /** * Gets the default display value. * * @return the default display value */ private static String getDefaultDisplayValue() { return getCharsetDisplayValue( getDefaultRawValue() ); } /** * Gets the default raw value, always the platform's * default encoding. * * @return the default raw value */ private static String getDefaultRawValue() { return BrowserCoreConstants.DEFAULT_ENCODING; } /** * Gets the other display values. * * @return the other display values */ private static String[] getOtherDisplayValues() { String[] otherEncodingsRawValues = getOtherRawValues(); String[] otherEncodingsDisplayValues = new String[otherEncodingsRawValues.length]; for ( int i = 0; i < otherEncodingsDisplayValues.length; i++ ) { String rawValue = otherEncodingsRawValues[i]; otherEncodingsDisplayValues[i] = getCharsetDisplayValue( rawValue ); } return otherEncodingsDisplayValues; } /** * Gets the other raw values. That are all values * returned from {@link Charset#availableCharsets()}. * * @return the other raw values */ private static String[] getOtherRawValues() { String[] otherEncodingsRawValues = ( String[] ) Charset.availableCharsets().keySet().toArray( new String[0] ); return otherEncodingsRawValues; } /** * Gets the charset display value. * * @param charsetRawValue the charset raw value * * @return the charset display value */ private static String getCharsetDisplayValue( String charsetRawValue ) { try { Charset charset = Charset.forName( charsetRawValue ); return charset.displayName(); } catch ( Exception e ) { return charsetRawValue; } } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/OptionsInput.java
plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/OptionsInput.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.ldapbrowser.common.widgets; import java.util.Arrays; import org.apache.directory.studio.common.ui.widgets.AbstractWidget; import org.apache.directory.studio.common.ui.widgets.BaseWidgetUtils; import org.apache.directory.studio.ldapbrowser.common.dialogs.preferences.TextFormatsPreferencePage; 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.widgets.Button; import org.eclipse.swt.widgets.Combo; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Group; /** * The OptionsInput could be used to select one option out of several options. * It consists of two radio buttons. With the first radio button you could * select the most likely default option. With the second radio button a combo * is activated where you could select another option from a drop-down list. * <p> * Both, the default option and the options in the drop-down list have a raw * value that is returned by {@link #getRawValue()} and a display value * that is shown to the user. * <p> * If the initial raw value is equal to the default raw value then the * default radio is checked and the drop-down list is disabled. Otherwise * the second radio is checked, the drop-down list is enabled and the * initial value is selected. * <p> * The OptionsInput is used by {@link TextFormatsPreferencePage}. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class OptionsInput extends AbstractWidget { /** The option's title */ private String title; /** The group, only used when asGroup is true */ private Group titleGroup; /** The default raw value */ private String defaultRawValue; /** The default display value */ private String defaultDisplayValue; /** The radio button to select the default value */ private Button defaultButton; /** The other raw values */ private String[] otherRawValues; /** The other display values */ private String[] otherDisplayValues; /** The radio button to select a value from drop-down list */ private Button otherButton; /** The combo with the other values */ private Combo otherCombo; /** The initial raw value */ private String initialRawValue; /** If true the options are aggregated in a group widget */ private boolean asGroup; /** If true it is possible to enter a custom value into the combo field */ private boolean allowCustomInput; /** * Creates a new instance of OptionsInput. * * @param title the option's title * @param defaultDisplayValue the default display value * @param defaultRawValue the default raw value * @param otherDisplayValues the other display values * @param otherRawValues the other raw vaues * @param initialRawValue the initial raw value * @param asGroup a flag indicating if the options should be * aggregated in a group widget * @param allowCustomInput true to make it possible to enter a * custom value into the combo field */ public OptionsInput( String title, String defaultDisplayValue, String defaultRawValue, String[] otherDisplayValues, String[] otherRawValues, String initialRawValue, boolean asGroup, boolean allowCustomInput ) { super(); this.title = title; this.defaultDisplayValue = defaultDisplayValue; this.defaultRawValue = defaultRawValue; this.otherDisplayValues = otherDisplayValues; this.otherRawValues = otherRawValues; this.initialRawValue = initialRawValue; this.asGroup = asGroup; this.allowCustomInput = allowCustomInput; } /** * Creates the widget. * * @param parent the parent */ public void createWidget( Composite parent ) { Composite composite; if ( asGroup ) { titleGroup = BaseWidgetUtils.createGroup( parent, title, 1 ); composite = BaseWidgetUtils.createColumnContainer( titleGroup, 1, 1 ); } else { composite = parent; Composite labelComposite = BaseWidgetUtils.createColumnContainer( composite, 1, 1 ); BaseWidgetUtils.createLabel( labelComposite, title + ":", 1 ); //$NON-NLS-1$ } Composite defaultComposite = BaseWidgetUtils.createColumnContainer( composite, 1, 1 ); defaultButton = BaseWidgetUtils.createRadiobutton( defaultComposite, defaultDisplayValue, 1 ); defaultButton.addSelectionListener( new SelectionAdapter() { public void widgetSelected( SelectionEvent e ) { otherButton.setSelection( false ); otherCombo.setEnabled( false ); notifyListeners(); } } ); Composite otherComposite = BaseWidgetUtils.createColumnContainer( composite, 2, 1 ); otherButton = BaseWidgetUtils.createRadiobutton( otherComposite, Messages.getString( "OptionsInput.Other" ), 1 ); //$NON-NLS-1$ otherButton.addSelectionListener( new SelectionAdapter() { public void widgetSelected( SelectionEvent e ) { defaultButton.setSelection( false ); otherCombo.setEnabled( true ); notifyListeners(); } } ); if ( allowCustomInput ) { otherCombo = BaseWidgetUtils.createCombo( otherComposite, otherDisplayValues, 0, 1 ); } else { otherCombo = BaseWidgetUtils.createReadonlyCombo( otherComposite, otherDisplayValues, 0, 1 ); } otherCombo.addModifyListener( new ModifyListener() { public void modifyText( ModifyEvent e ) { notifyListeners(); } } ); setRawValue( initialRawValue ); } /** * Gets the raw value. Either the default value or * the selected value from the combo. * * @return the raw value */ public String getRawValue() { if ( defaultButton.getSelection() ) { return defaultRawValue; } else { String t = otherCombo.getText(); for ( int i = 0; i < otherDisplayValues.length; i++ ) { if ( t.equals( otherDisplayValues[i] ) ) { return otherRawValues[i]; } } return t; } } /** * Sets the raw value. * * @param rawValue the raw value */ public void setRawValue( String rawValue ) { int index = Arrays.asList( otherRawValues ).indexOf( rawValue ); if ( index == -1 ) { index = Arrays.asList( otherDisplayValues ).indexOf( rawValue ); } if ( defaultRawValue.equals( rawValue ) ) { defaultButton.setSelection( true ); otherButton.setSelection( false ); otherCombo.setEnabled( false ); otherCombo.select( index ); } else if ( index > -1 ) { defaultButton.setSelection( false ); otherButton.setSelection( true ); otherCombo.setEnabled( true ); otherCombo.select( index ); } else { defaultButton.setSelection( false ); otherButton.setSelection( true ); otherCombo.setEnabled( true ); otherCombo.setText( rawValue ); } } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/DialogContentAssistant.java
plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/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.ldapbrowser.common.widgets; 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; /** * The DialogContentAssistant is used to provide content assist and * a proposal popup within a SWT {@link Text}, {@link Combo} or * {@link ITextViewer}. * * It provides a special handling of ESC keystrokes: * When the proposal popup is shown ESC is catched and the popup is closed. * This ensures that a dialog isn't closed on a ESC keystroke * while the proposal popup is opened. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class DialogContentAssistant extends SubjectControlContentAssistant implements FocusListener { /** The control */ private Control control; /** The handler activation. */ private IHandlerActivation handlerActivation; /** The possible completions visible. */ private boolean possibleCompletionsVisible; /** * Creates a new instance of DialogContentAssistant. */ public DialogContentAssistant() { this.possibleCompletionsVisible = false; } /** * Installs content assist on the given text. * * @param text the text */ public void install( Text text ) { control = text; control.addFocusListener( this ); super.install( new TextContentAssistSubjectAdapter( text ) ); } /** * Installs content assist on the given combo. * * @param combo the combo */ public void install( Combo combo ) { control = combo; control.addFocusListener( this ); super.install( new ComboContentAssistSubjectAdapter( combo ) ); } /** * Installs content assist on the given text viewer. * * @param viewer the text viewer */ public void install( ITextViewer viewer ) { control = viewer.getTextWidget(); control.addFocusListener( this ); // stop traversal (ESC) if popup is shown control.addTraverseListener( new TraverseListener() { public void keyTraversed( TraverseEvent e ) { if ( possibleCompletionsVisible ) { e.doit = false; } } } ); super.install( viewer ); } /** * Uninstalls content assist on the control. */ public void uninstall() { if ( handlerActivation != null ) { IHandlerService handlerService = ( IHandlerService ) PlatformUI.getWorkbench().getAdapter( IHandlerService.class ); handlerService.deactivateHandler( handlerActivation ); handlerActivation = null; } if ( control != null ) { 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() { 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; } }; handlerActivation = handlerService.activateHandler( ITextEditorActionDefinitionIds.CONTENT_ASSIST_PROPOSALS, handler ); } } /** * {@inheritDoc} */ public void focusLost( FocusEvent e ) { if ( handlerActivation != null ) { IHandlerService handlerService = ( IHandlerService ) PlatformUI.getWorkbench().getAdapter( IHandlerService.class ); handlerService.deactivateHandler( handlerActivation ); 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/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/Messages.java
plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/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.ldapbrowser.common.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 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/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/DnBuilderWidget.java
plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/DnBuilderWidget.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.ldapbrowser.common.widgets; import java.util.ArrayList; import java.util.Arrays; import java.util.Iterator; import org.apache.directory.api.ldap.model.exception.LdapInvalidDnException; import org.apache.directory.api.ldap.model.name.Ava; import org.apache.directory.api.ldap.model.name.Dn; import org.apache.directory.api.ldap.model.name.Rdn; import org.apache.directory.studio.common.ui.widgets.AbstractWidget; import org.apache.directory.studio.common.ui.widgets.BaseWidgetUtils; import org.apache.directory.studio.connection.core.DnUtils; import org.apache.directory.studio.connection.ui.widgets.ExtendedContentAssistCommandAdapter; import org.apache.directory.studio.ldapbrowser.common.widgets.search.EntryWidget; import org.apache.directory.studio.ldapbrowser.core.model.IBrowserConnection; import org.eclipse.jface.fieldassist.ComboContentAdapter; import org.eclipse.jface.fieldassist.ContentProposalAdapter; import org.eclipse.swt.SWT; import org.eclipse.swt.events.ModifyEvent; import org.eclipse.swt.events.ModifyListener; import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.events.SelectionListener; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.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.Shell; import org.eclipse.swt.widgets.Text; /** * The DnBuilderWidget provides input elements to select a parent Dn * and to build a (multivalued) Rdn. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class DnBuilderWidget extends AbstractWidget implements ModifyListener { /** The attribute names that could be selected from drop-down list. */ private String[] attributeNames; /** True if the Rdn input elements should be shown. */ private boolean showRDN; /** True if the parent Dn input elements should be shown. */ private boolean showParent; /** The shell. */ private Shell shell; /** The selected parent Dn. */ private Dn parentDn; /** The entry widget label. */ private Label parentEntryLabel; /** The entry widget to enter/select the parent Dn. */ private EntryWidget parentEntryWidget; /** The Rdn label */ private Label rdnLabel; /** The composite that contains the RdnLines. */ private Composite rdnComposite; /** The resulting Rdn. */ private Rdn rdn; /** The list of RdnLines. */ private ArrayList<RdnLine> rdnLineList; /** The preview label. */ private Label previewLabel; /** The preview text. */ private Text previewText; // Listeners private SelectionListener rdnAddButtonSelectionListener = new SelectionAdapter() { @Override public void widgetSelected( SelectionEvent e ) { int index = rdnLineList.size(); for ( int i = 0; i < rdnLineList.size(); i++ ) { RdnLine rdnLine = rdnLineList.get( i ); if ( rdnLine.rdnAddButton == e.widget ) { index = i + 1; } } addRdnLine( rdnComposite, index ); validate(); } }; private SelectionListener rdnDeleteButtonSelectionListener = new SelectionAdapter() { @Override public void widgetSelected( SelectionEvent e ) { int index = 0; for ( int i = 0; i < rdnLineList.size(); i++ ) { RdnLine rdnLine = rdnLineList.get( i ); if ( rdnLine.rdnDeleteButton == e.widget ) { index = i; } } deleteRdnLine( rdnComposite, index ); validate(); } }; /** * Creates a new instance of DnBuilderWidget. * * @param showParent true if the parent Dn input elements should be shown * @param showRDN true if the Rdn input elements should be shown */ public DnBuilderWidget( boolean showRDN, boolean showParent ) { this.showRDN = showRDN; this.showParent = showParent; } /** * Disposes this widget. */ public void dispose() { } /** * Sets the input. * * @param rdn the initial Rdn * @param attributeNames the attribute names that could be selected from drop-down list * @param browserConnection the connection * @param parentDn the initial parent Dn */ public void setInput( IBrowserConnection browserConnection, String[] attributeNames, Rdn rdn, Dn parentDn ) { this.attributeNames = attributeNames; Rdn currentRdn = rdn; Dn currentParentDn = parentDn; if ( showRDN ) { for ( int i = 0; i < rdnLineList.size(); i++ ) { RdnLine rdnLine = rdnLineList.get( i ); String oldName = rdnLine.rdnTypeCombo.getText(); rdnLine.rdnTypeCombo.setItems( attributeNames ); rdnLine.rdnNameCPA.setContentProposalProvider( new ListContentProposalProvider( attributeNames ) ); if ( Arrays.asList( rdnLine.rdnTypeCombo.getItems() ).contains( oldName ) ) { rdnLine.rdnTypeCombo.setText( oldName ); } } } if ( showRDN ) { while ( !rdnLineList.isEmpty() ) { deleteRdnLine( rdnComposite, 0 ); } if ( currentRdn == null || currentRdn.size() == 0 ) { addRdnLine( rdnComposite, 0 ); rdnLineList.get( 0 ).rdnTypeCombo.setFocus(); } else { int i = 0; Iterator<Ava> atavIterator = currentRdn.iterator(); while ( atavIterator.hasNext() ) { Ava ava = atavIterator.next(); addRdnLine( rdnComposite, i ); removeRdnLineListeners( i ); rdnLineList.get( i ).rdnTypeCombo.setText( ava.getType() ); rdnLineList.get( i ).rdnValueText.setText( (String)ava.getValue().getNormalized() ); addRdnLineListeners( i ); if ( i == 0 ) { RdnLine rdnLine = rdnLineList.get( i ); if ( rdnLine.rdnTypeCombo != null ) //$NON-NLS-1$ { rdnLine.rdnTypeCombo.setFocus(); } else { rdnLine.rdnValueText.selectAll(); rdnLine.rdnValueText.setFocus(); } } i++; } } } if ( showParent ) { parentEntryWidget.setInput( browserConnection, currentParentDn ); } validate(); } /** * Gets the Rdn. * * @return the Rdn */ public Rdn getRdn() { return rdn; } /** * Gets the parent Dn. * * @return the parent Dn */ public Dn getParentDn() { return parentDn; } /** * Creates the contents. * * @param parent the parent composite * * @return the created composite */ public Composite createContents( Composite parent ) { this.shell = parent.getShell(); Composite composite = BaseWidgetUtils.createColumnContainer( parent, 3, 1 ); // draw parent if ( showParent ) { parentEntryLabel = BaseWidgetUtils.createLabel( composite, Messages.getString( "DnBuilderWidget.Parent" ), 1 ); //$NON-NLS-1$ parentEntryWidget = new EntryWidget(); parentEntryWidget.createWidget( composite ); parentEntryWidget.addWidgetModifyListener( event -> validate() ); BaseWidgetUtils.createSpacer( composite, 3 ); } // draw Rdn group if ( showRDN ) { rdnLabel = BaseWidgetUtils.createLabel( composite, Messages.getString( "DnBuilderWidget.RDN" ), 1 ); //$NON-NLS-1$ rdnComposite = BaseWidgetUtils.createColumnContainer( composite, 5, 2 ); rdnLineList = new ArrayList<>(); BaseWidgetUtils.createSpacer( composite, 3 ); } // draw dn/rdn preview if ( showRDN ) { previewLabel = BaseWidgetUtils.createLabel( composite, showParent ? Messages .getString( "DnBuilderWidget.DNPreview" ) : Messages.getString( "DnBuilderWidget.RDNPreview" ), 1 ); //$NON-NLS-1$ //$NON-NLS-2$ previewText = BaseWidgetUtils.createReadonlyText( composite, "", 2 ); //$NON-NLS-1$ BaseWidgetUtils.createSpacer( composite, 3 ); } return composite; } /** * {@inheritDoc} */ public void modifyText( ModifyEvent e ) { validate(); } /** * Saves the dialog settings. */ public void saveDialogSettings() { if ( parentEntryWidget != null ) { parentEntryWidget.saveDialogSettings(); } } /** * Validates the input elements. */ public void validate() { Exception rdnE = null; if ( showRDN ) { try { // calculate Rdn String[] rdnTypes = new String[rdnLineList.size()]; String[] rdnValues = new String[rdnLineList.size()]; for ( int i = 0; i < rdnLineList.size(); i++ ) { RdnLine rdnLine = rdnLineList.get( i ); rdnTypes[i] = rdnLine.rdnTypeCombo.getText(); rdnValues[i] = rdnLine.rdnValueText.getText(); if ( rdnLineList.size() > 1 ) { rdnLine.rdnDeleteButton.setEnabled( true ); } else { rdnLine.rdnDeleteButton.setEnabled( false ); } } rdn = DnUtils.composeRdn( rdnTypes, rdnValues ); } catch ( Exception e ) { rdnE = e; rdn = null; } } Exception parentE = null; if ( showParent ) { try { // calculate Dn parentDn = parentEntryWidget.getDn(); } catch ( Exception e ) { parentE = e; parentDn = null; } } String s = ""; //$NON-NLS-1$ if ( rdnE != null ) { s += rdnE.getMessage() != null ? rdnE.getMessage() : Messages.getString( "DnBuilderWidget.ErrorInRDN" ); //$NON-NLS-1$ } if ( parentE != null ) { s += ", " + parentE.getMessage() != null ? parentE.getMessage() : Messages.getString( "DnBuilderWidget.ErrorInParentDN" ); //$NON-NLS-1$ //$NON-NLS-2$ } if ( previewText != null ) { if ( s.length() > 0 ) { previewText.setText( s ); } else { Dn dn; if ( showParent && showRDN ) { try { dn = parentDn.add( rdn ); } catch ( LdapInvalidDnException lide ) { // Do nothing dn = Dn.EMPTY_DN; } } else if ( showParent ) { dn = parentDn; } else if ( showRDN ) { try { dn = new Dn( rdn ); } catch ( LdapInvalidDnException lide ) { // Do nothing dn = Dn.EMPTY_DN; } } else { dn = Dn.EMPTY_DN; } previewText.setText( dn.getName() ); } } notifyListeners(); } /** * Adds an Rdn line at the given index. * * @param rdnComposite the Rdn composite * @param index the index */ private void addRdnLine( Composite rdnComposite, int index ) { RdnLine[] rdnLines = rdnLineList.toArray( new RdnLine[rdnLineList.size()] ); if ( rdnLines.length > 0 ) { for ( int i = 0; i < rdnLines.length; i++ ) { RdnLine oldRdnLine = rdnLines[i]; // remember values String oldName = oldRdnLine.rdnTypeCombo.getText(); String oldValue = oldRdnLine.rdnValueText.getText(); // delete old oldRdnLine.rdnTypeCombo.dispose(); oldRdnLine.rdnEqualsLabel.dispose(); oldRdnLine.rdnValueText.dispose(); oldRdnLine.rdnAddButton.dispose(); oldRdnLine.rdnDeleteButton.dispose(); rdnLineList.remove( oldRdnLine ); // add new RdnLine newRdnLine = createRdnLine( rdnComposite ); rdnLineList.add( newRdnLine ); // restore value newRdnLine.rdnTypeCombo.setText( oldName ); newRdnLine.rdnValueText.setText( oldValue ); // check if ( index == i + 1 ) { RdnLine rdnLine = createRdnLine( rdnComposite ); rdnLineList.add( rdnLine ); } } } else { RdnLine rdnLine = createRdnLine( rdnComposite ); rdnLineList.add( rdnLine ); } shell.layout( true, true ); } /** * Creates and returns an Rdn line. * * @param rdnComposite the Rdn composite * * @return the created Rdn line */ private RdnLine createRdnLine( final Composite rdnComposite ) { final RdnLine rdnLine = new RdnLine(); rdnLine.rdnTypeCombo = new Combo( rdnComposite, SWT.DROP_DOWN | SWT.BORDER ); GridData gd = new GridData(); gd.widthHint = 180; rdnLine.rdnTypeCombo.setLayoutData( gd ); rdnLine.rdnNameCPA = new ExtendedContentAssistCommandAdapter( rdnLine.rdnTypeCombo, new ComboContentAdapter(), new ListContentProposalProvider( attributeNames ), null, null, true ); rdnLine.rdnEqualsLabel = new Label( rdnComposite, SWT.NONE ); rdnLine.rdnEqualsLabel.setText( "=" ); //$NON-NLS-1$ rdnLine.rdnValueText = new Text( rdnComposite, SWT.BORDER ); gd = new GridData( GridData.FILL_HORIZONTAL | GridData.GRAB_HORIZONTAL ); rdnLine.rdnValueText.setLayoutData( gd ); rdnLine.rdnAddButton = new Button( rdnComposite, SWT.PUSH ); rdnLine.rdnAddButton.setText( " + " ); //$NON-NLS-1$ rdnLine.rdnDeleteButton = new Button( rdnComposite, SWT.PUSH ); rdnLine.rdnDeleteButton.setText( " \u2212 " ); //$NON-NLS-1$ if ( attributeNames != null ) { rdnLine.rdnTypeCombo.setItems( attributeNames ); } addRdnLineListeners( rdnLine ); return rdnLine; } /** * Delete the Rdn line on the given index. * * @param rdnComposite the Rdn composite * @param index the index */ private void deleteRdnLine( Composite rdnComposite, int index ) { RdnLine rdnLine = rdnLineList.remove( index ); if ( rdnLine != null ) { rdnLine.rdnTypeCombo.dispose(); rdnLine.rdnEqualsLabel.dispose(); rdnLine.rdnValueText.dispose(); rdnLine.rdnAddButton.dispose(); rdnLine.rdnDeleteButton.dispose(); if ( !rdnComposite.isDisposed() ) { shell.layout( true, true ); } } } /** * Adds listeners for the Rdn line at the given index. * * @param index the index */ private void addRdnLineListeners( int index ) { if ( rdnLineList != null ) { addRdnLineListeners( rdnLineList.get( index ) ); } } /** * Adds listeners for the Rdn line. * * @param rdnLine the Rdn line */ private void addRdnLineListeners( RdnLine rdnLine ) { if ( rdnLine != null ) { rdnLine.rdnAddButton.addSelectionListener( rdnAddButtonSelectionListener ); rdnLine.rdnDeleteButton.addSelectionListener( rdnDeleteButtonSelectionListener ); rdnLine.rdnTypeCombo.addModifyListener( this ); rdnLine.rdnValueText.addModifyListener( this ); } } /** * Removes listeners for the Rdn line at the given index. * * @param index the index */ private void removeRdnLineListeners( int index ) { if ( rdnLineList != null ) { removeRdnLineListeners( rdnLineList.get( index ) ); } } /** * Removes listeners for the Rdn line. * * @param rdnLine the Rdn line */ private void removeRdnLineListeners( RdnLine rdnLine ) { if ( rdnLine != null ) { rdnLine.rdnAddButton.removeSelectionListener( rdnAddButtonSelectionListener ); rdnLine.rdnDeleteButton.removeSelectionListener( rdnDeleteButtonSelectionListener ); rdnLine.rdnTypeCombo.removeModifyListener( this ); rdnLine.rdnValueText.removeModifyListener( this ); } } /** * The Class RdnLine is a wrapper for all input elements * of an Rdn line. It contains a combo for the Rdn attribute, * an input field for the Rdn value and + and - buttons * to add and remove other Rdn lines. It looks like this: * <pre> * -------------------------------------------------- * | attribute type v | = | attribute value | + | - | * -------------------------------------------------- * </pre> */ private class RdnLine { /** The rdn name combo. */ private Combo rdnTypeCombo; /** The content proposal adapter */ private ContentProposalAdapter rdnNameCPA; /** The rdn value text. */ private Text rdnValueText; /** The rdn equals label. */ private Label rdnEqualsLabel; /** The rdn add button. */ private Button rdnAddButton; /** The rdn delete button. */ private Button rdnDeleteButton; } /** * Enables or disables this widget. * * @param b true to enable, false to disable */ public void setEnabled( boolean b ) { if ( parentEntryWidget != null ) { parentEntryLabel.setEnabled( b ); parentEntryWidget.setEnabled( b ); } if ( rdnComposite != null && rdnLineList != null ) { rdnLabel.setEnabled( b ); rdnComposite.setEnabled( b ); for ( RdnLine rdnLine : rdnLineList ) { rdnLine.rdnTypeCombo.setEnabled( b ); rdnLine.rdnEqualsLabel.setEnabled( b ); rdnLine.rdnValueText.setEnabled( b ); rdnLine.rdnAddButton.setEnabled( b ); rdnLine.rdnDeleteButton.setEnabled( b && rdnLineList.size() > 1 ); } if ( b ) { rdnLineList.get( 0 ).rdnValueText.setFocus(); } } if ( previewText != null ) { previewLabel.setEnabled( b ); previewText.setEnabled( b ); } } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/FileBrowserWidget.java
plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/FileBrowserWidget.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.ldapbrowser.common.widgets; import java.io.File; import org.apache.directory.studio.common.ui.HistoryUtils; import org.apache.directory.studio.common.ui.widgets.AbstractWidget; import org.apache.directory.studio.common.ui.widgets.BaseWidgetUtils; import org.apache.directory.studio.ldapbrowser.common.BrowserCommonActivator; import org.apache.directory.studio.ldapbrowser.common.BrowserCommonConstants; 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.widgets.Button; import org.eclipse.swt.widgets.Combo; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.FileDialog; /** * The FileBrowserWidget provides a combo with a history of recently * used files and a browse button to open the file browser. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class FileBrowserWidget extends AbstractWidget { /** The Constant TYPE_OPEN is used to create a Open file dialog. */ public static final int TYPE_OPEN = SWT.OPEN; /** The Constant TYPE_SAVE is used to create a Save file dialog. */ public static final int TYPE_SAVE = SWT.SAVE; /** The combo with the history of recently used files */ protected Combo fileCombo; /** The button to launch the file browser */ protected Button browseButton; /** The title */ protected String title; /** File extensions used within the launched file browser */ protected String[] extensions; /** The type */ protected int type; /** * Creates a new instance of FileBrowserWidget. * * @param title The title * @param extensions The valid file extensions * @param type The type, one of {@link #TYPE_OPEN} or {@link #TYPE_SAVE} */ public FileBrowserWidget( String title, String[] extensions, int type ) { this.title = title; this.extensions = extensions; this.type = type; } /** * Creates the widget. * * @param parent the parent */ public void createWidget( Composite parent ) { // Combo fileCombo = new Combo( parent, SWT.DROP_DOWN | SWT.BORDER ); GridData gd = new GridData( GridData.FILL_HORIZONTAL ); gd.widthHint = 50; fileCombo.setLayoutData( gd ); fileCombo.setVisibleItemCount( 20 ); fileCombo.addModifyListener( new ModifyListener() { public void modifyText( ModifyEvent e ) { notifyListeners(); } } ); // Button browseButton = BaseWidgetUtils.createButton( parent, Messages.getString( "FileBrowserWidget.BrowseButton" ), 1 ); //$NON-NLS-1$ browseButton.addSelectionListener( new SelectionAdapter() { public void widgetSelected( SelectionEvent event ) { FileDialog fileDialog = new FileDialog( browseButton.getShell(), type ); fileDialog.setText( title ); fileDialog.setFilterExtensions( extensions ); File file = new File( fileCombo.getText() ); if ( file.isFile() ) { fileDialog.setFilterPath( file.getParent() ); fileDialog.setFileName( file.getName() ); } else if ( file.isDirectory() ) { fileDialog.setFilterPath( file.getPath() ); } else { fileDialog.setFilterPath( BrowserCommonActivator.getDefault().getDialogSettings().get( BrowserCommonConstants.DIALOGSETTING_KEY_RECENT_FILE_PATH ) ); } String returnedFileName = fileDialog.open(); if ( returnedFileName != null ) { fileCombo.setText( returnedFileName ); File file2 = new File( returnedFileName ); BrowserCommonActivator.getDefault().getDialogSettings().put( BrowserCommonConstants.DIALOGSETTING_KEY_RECENT_FILE_PATH, file2.getParent() ); } } } ); // file history String[] history = HistoryUtils.load( BrowserCommonActivator.getDefault().getDialogSettings(), BrowserCommonConstants.DIALOGSETTING_KEY_FILE_HISTORY ); fileCombo.setItems( history ); } /** * Gets the filename. * * @return the filename */ public String getFilename() { return fileCombo.getText(); } /** * Sets the filename. * * @param filename the filename */ public void setFilename( String filename ) { fileCombo.setText( filename ); } /** * Saves dialog settings. */ public void saveDialogSettings() { HistoryUtils.save( BrowserCommonActivator.getDefault().getDialogSettings(), BrowserCommonConstants.DIALOGSETTING_KEY_FILE_HISTORY, fileCombo.getText() ); } /** * Sets the focus. */ public void setFocus() { fileCombo.setFocus(); } /** * Enables or disables the widget. * * @param b true to enable the widget, false otherwise */ public void setEnabled( boolean b ) { fileCombo.setEnabled( b ); browseButton.setEnabled( b ); } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/LineSeparatorInput.java
plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/LineSeparatorInput.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.ldapbrowser.common.widgets; import java.util.Iterator; import java.util.Map; import org.apache.directory.studio.ldapbrowser.core.BrowserCoreConstants; import org.eclipse.core.runtime.Platform; /** * The LineSeparatorInput is an OptionInput with fixed options. * It is used to select the line separator. The default * value is always the platform's default line separator. * The other options are the values return from * {@link Platform#knownPlatformLineSeparators()}. * No custom input is allowed. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class LineSeparatorInput extends OptionsInput { /** * Creates a new instance of LineSeparatorInput. * * @param initialRawValue the initial raw value * @param asGroup the asGroup flag */ public LineSeparatorInput( String initialRawValue, boolean asGroup ) { super( Messages.getString( "LineSeparatorInput.LineSeparator" ), getDefaultDisplayValue(), getDefaultRawValue(), getOtherDisplayValues(), //$NON-NLS-1$ getOtherRawValues(), initialRawValue, asGroup, false ); } /** * Gets the default display value. * * @return the default display value */ private static String getDefaultDisplayValue() { Map lsMap = Platform.knownPlatformLineSeparators(); for ( Iterator iter = lsMap.keySet().iterator(); iter.hasNext(); ) { String k = ( String ) iter.next(); String v = ( String ) lsMap.get( k ); if ( v.equals( getDefaultRawValue() ) ) { k = k + " (" + ( v.replaceAll( "\n", "\\\\n" ).replaceAll( "\r", "\\\\r" ) ) + ")"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ return k; } } return getDefaultRawValue(); } /** * Gets the default raw value, always the platform's default * line separator. * * @return the default raw value */ private static String getDefaultRawValue() { return BrowserCoreConstants.LINE_SEPARATOR; } /** * Gets the other display values That are all values * returned from {@link Platform#knownPlatformLineSeparators()}. * * @return the other display values */ @SuppressWarnings("unchecked") private static String[] getOtherDisplayValues() { Map<String, String> lsMap = Platform.knownPlatformLineSeparators(); String[] displayValues = lsMap.keySet().toArray( new String[lsMap.size()] ); for ( int i = 0; i < displayValues.length; i++ ) { displayValues[i] = displayValues[i] + " (" //$NON-NLS-1$ + ( ( ( String ) lsMap.get( displayValues[i] ) ).replaceAll( "\n", "\\\\n" ).replaceAll( "\r", "\\\\r" ) ) //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ + ")"; //$NON-NLS-1$ } return displayValues; } /** * Gets the other raw values. * * @return the other raw values */ @SuppressWarnings("unchecked") private static String[] getOtherRawValues() { Map<String, String> lsMap = Platform.knownPlatformLineSeparators(); String[] displayValues = lsMap.keySet().toArray( new String[lsMap.size()] ); String[] rawValues = new String[displayValues.length]; for ( int i = 0; i < rawValues.length; i++ ) { rawValues[i] = ( String ) lsMap.get( displayValues[i] ); } return rawValues; } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/entryeditor/EntryEditorWidgetSorter.java
plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/entryeditor/EntryEditorWidgetSorter.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.ldapbrowser.common.widgets.entryeditor; import java.util.Arrays; import java.util.Comparator; import org.apache.directory.studio.ldapbrowser.common.BrowserCommonActivator; import org.apache.directory.studio.ldapbrowser.common.BrowserCommonConstants; import org.apache.directory.studio.ldapbrowser.core.BrowserCoreConstants; import org.apache.directory.studio.ldapbrowser.core.utils.AttributeComparator; import org.eclipse.jface.viewers.TreeViewer; import org.eclipse.jface.viewers.Viewer; import org.eclipse.jface.viewers.ViewerSorter; import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.events.SelectionListener; import org.eclipse.swt.widgets.Tree; import org.eclipse.swt.widgets.TreeColumn; /** * The EntryEditorWidgetSorter implements the Sorter for the entry editor widget. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class EntryEditorWidgetSorter extends ViewerSorter implements SelectionListener { /** The tree viewer. */ private TreeViewer viewer; /** The sort property. */ private int sortBy; /** The sort order. */ private int sortOrder; /** The preferences. */ private EntryEditorWidgetPreferences preferences; /** * Creates a new instance of EntryEditorWidgetSorter. * * @param preferences the preferences */ public EntryEditorWidgetSorter( EntryEditorWidgetPreferences preferences ) { this.sortBy = BrowserCoreConstants.SORT_BY_NONE; this.sortOrder = BrowserCoreConstants.SORT_ORDER_NONE; this.preferences = preferences; } /** * Connects this sorter to the given tree viewer. * * @param viewer the viewer */ public void connect( TreeViewer viewer ) { this.viewer = viewer; viewer.setSorter( this ); for ( TreeColumn column : ( ( TreeViewer ) viewer ).getTree().getColumns() ) { column.addSelectionListener( this ); } } /** * Disposes this sorter. */ public void dispose() { viewer = null; preferences = null; } /** * {@inheritDoc} */ public void widgetDefaultSelected( SelectionEvent e ) { } /** * {@inheritDoc} * * Switches the sort property and sort order when clicking the table headers. */ public void widgetSelected( SelectionEvent event ) { if ( ( event.widget instanceof TreeColumn ) && ( viewer != null ) ) { Tree tree = viewer.getTree(); TreeColumn treeColumn = ( ( TreeColumn ) event.widget ); int index = tree.indexOf( treeColumn ); switch ( index ) { case EntryEditorWidgetTableMetadata.KEY_COLUMN_INDEX: if ( sortBy == BrowserCoreConstants.SORT_BY_ATTRIBUTE_DESCRIPTION ) { toggleSortOrder(); } else { // set new sort by sortBy = BrowserCoreConstants.SORT_BY_ATTRIBUTE_DESCRIPTION; sortOrder = BrowserCoreConstants.SORT_ORDER_ASCENDING; } break; case EntryEditorWidgetTableMetadata.VALUE_COLUMN_INDEX: if ( sortBy == BrowserCoreConstants.SORT_BY_VALUE ) { toggleSortOrder(); } else { // set new sort by sortBy = BrowserCoreConstants.SORT_BY_VALUE; sortOrder = BrowserCoreConstants.SORT_ORDER_ASCENDING; } break; default:; } if ( sortOrder == BrowserCoreConstants.SORT_ORDER_NONE ) { sortBy = BrowserCoreConstants.SORT_BY_NONE; } for ( TreeColumn column : tree.getColumns() ) { column.setImage( null ); } if ( sortOrder == BrowserCoreConstants.SORT_ORDER_ASCENDING ) { treeColumn.setImage( BrowserCommonActivator.getDefault().getImage( BrowserCommonConstants.IMG_SORT_ASCENDING ) ); } else if ( sortOrder == BrowserCoreConstants.SORT_ORDER_DESCENDING ) { treeColumn.setImage( BrowserCommonActivator.getDefault().getImage( BrowserCommonConstants.IMG_SORT_DESCENDING ) ); } viewer.refresh(); } } /** * Rotate the sort order. If it was none, change it to ascending. If it was * ascending, change it to descending, and if it was descending, change it to none. */ private void toggleSortOrder() { switch ( sortOrder ) { case BrowserCoreConstants.SORT_ORDER_NONE: sortOrder = BrowserCoreConstants.SORT_ORDER_ASCENDING; break; case BrowserCoreConstants.SORT_ORDER_ASCENDING: sortOrder = BrowserCoreConstants.SORT_ORDER_DESCENDING; break; case BrowserCoreConstants.SORT_ORDER_DESCENDING: sortOrder = BrowserCoreConstants.SORT_ORDER_NONE; break; } } /** * {@inheritDoc} */ public void sort( final Viewer viewer, Object[] elements ) { Arrays.sort( elements, new Comparator<Object>() { public int compare( Object a, Object b ) { return EntryEditorWidgetSorter.this.compare( viewer, a, b ); } } ); } /** * {@inheritDoc} */ public int compare( Viewer viewer, Object o1, Object o2 ) { boolean objectClassAndMustAttributesFirst = preferences == null || preferences.isObjectClassAndMustAttributesFirst(); boolean operationalAttributesLast = preferences == null || preferences.isOperationalAttributesLast(); AttributeComparator comparator = new AttributeComparator( sortBy, getDefaultSortBy(), sortOrder, getDefaultSortOrder(), objectClassAndMustAttributesFirst, operationalAttributesLast ); return comparator.compare( o1, o2 ); } private int getDefaultSortOrder() { if ( preferences == null ) { return BrowserCoreConstants.SORT_ORDER_ASCENDING; } else { return preferences.getDefaultSortOrder(); } } private int getDefaultSortBy() { if ( preferences == null ) { return BrowserCoreConstants.SORT_BY_ATTRIBUTE_DESCRIPTION; } else { return preferences.getDefaultSortBy(); } } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/entryeditor/EntryEditorPasteAction.java
plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/entryeditor/EntryEditorPasteAction.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.ldapbrowser.common.widgets.entryeditor; import org.apache.directory.studio.common.ui.ClipboardUtils; import org.apache.directory.studio.ldapbrowser.common.actions.PasteAction; import org.apache.directory.studio.ldapbrowser.common.dnd.ValuesTransfer; import org.apache.directory.studio.ldapbrowser.core.model.AttributeHierarchy; import org.apache.directory.studio.ldapbrowser.core.model.IEntry; import org.apache.directory.studio.ldapbrowser.core.model.IValue; import org.apache.directory.studio.ldapbrowser.core.utils.CompoundModification; /** * This class implements the paste action for the tabular entry editor. * It copies attribute-values to another entry. * It does not invoke an UpdateEntryRunnable but only updates the model. */ public class EntryEditorPasteAction extends PasteAction { /** * Creates a new instance of EntryEditorPasteAction. */ public EntryEditorPasteAction() { super(); } /** * {@inheritDoc} */ public String getText() { IValue[] values = getValuesToPaste(); if ( values != null ) { return values.length > 1 ? Messages.getString( "EntryEditorPasteAction.PasteValues" ) : Messages.getString( "EntryEditorPasteAction.PasteValue" ); //$NON-NLS-1$ //$NON-NLS-2$ } return Messages.getString( "EntryEditorPasteAction.Paste" ); //$NON-NLS-1$ } /** * {@inheritDoc} */ public boolean isEnabled() { if ( getValuesToPaste() != null ) { return true; } return false; } /** * {@inheritDoc} */ public void run() { IValue[] values = getValuesToPaste(); if ( values != null ) { IEntry entry = null; if ( getInput() instanceof IEntry ) { entry = ( IEntry ) getInput(); } else if ( getInput() instanceof AttributeHierarchy ) { entry = ( ( AttributeHierarchy ) getInput() ).getEntry(); } if ( entry != null ) { // only modify the model // the modification at the directory is done by EntryEditorManager new CompoundModification().createValues( entry, values ); } } } /** * Conditions: * <li>the input is an entry or attribute hierarchy</li> * <li>there are values in clipboard</li> * * @return the values to paste */ private IValue[] getValuesToPaste() { if ( ( getInput() instanceof IEntry ) || ( getInput() instanceof AttributeHierarchy ) ) { Object content = ClipboardUtils.getFromClipboard( ValuesTransfer.getInstance() ); if ( content instanceof IValue[] ) { IValue[] values = ( IValue[] ) content; return values; } } 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/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/entryeditor/EntryEditorWidget.java
plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/entryeditor/EntryEditorWidget.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.ldapbrowser.common.widgets.entryeditor; import org.apache.directory.studio.common.ui.widgets.ViewFormWidget; import org.apache.directory.studio.valueeditors.ValueEditorManager; import org.eclipse.jface.viewers.CellEditor; import org.eclipse.jface.viewers.TreeViewer; import org.eclipse.swt.SWT; import org.eclipse.swt.events.ControlAdapter; import org.eclipse.swt.events.ControlEvent; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Tree; import org.eclipse.swt.widgets.TreeColumn; /** * The EntryEditorWidget is a reusable widget to display and edit the attributes of an entry. * It is used by * {@link org.apache.directory.studio.ldapbrowser.ui.editors.entry.EntryEditor}, * {@link org.apache.directory.studio.ldapbrowser.common.dialogs.MultivaluedDialog}, * {@link org.apache.directory.studio.ldapbrowser.common.dialogs.LdifEntryEditorDialog} and * {@link org.apache.directory.studio.ldapbrowser.common.wizards.NewEntryAttributesWizardPage}. * * It provides a context menu and a local toolbar with actions to * manage attributes. Further there is an instant search feature to filter * the visible attributes. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class EntryEditorWidget extends ViewFormWidget { /** The configuration. */ private EntryEditorWidgetConfiguration configuration; /** The quick filter widget. */ private EntryEditorWidgetQuickFilterWidget quickFilterWidget; /** The tree. */ private Tree tree; /** The viewer. */ private TreeViewer viewer; /** * Creates a new instance of EntryEditorWidget. * * @param configuration the configuration */ public EntryEditorWidget( EntryEditorWidgetConfiguration configuration ) { this.configuration = configuration; } /** * {@inheritDoc} */ protected Control createContent( Composite parent ) { // Create the filter widget quickFilterWidget = new EntryEditorWidgetQuickFilterWidget( configuration.getFilter(), this ); quickFilterWidget.createComposite( parent ); // create tree widget and viewer tree = new Tree( parent, SWT.VIRTUAL | SWT.MULTI | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.HIDE_SELECTION ); GridData data = new GridData( GridData.FILL_BOTH ); data.widthHint = 450; data.heightHint = 250; tree.setLayoutData( data ); tree.setHeaderVisible( true ); tree.setLinesVisible( true ); viewer = new TreeViewer( tree ); viewer.setUseHashlookup( true ); // set tree columns. We have 2 : one for the KEY, one for the Value for ( int i = 0; i < EntryEditorWidgetTableMetadata.COLUM_NAMES.length; i++ ) { TreeColumn column = new TreeColumn( tree, SWT.LEFT, i ); column.setText( EntryEditorWidgetTableMetadata.COLUM_NAMES[i] ); column.setWidth( 200 ); column.setResizable( true ); } viewer.setColumnProperties( EntryEditorWidgetTableMetadata.COLUM_NAMES ); tree.addControlListener( new ControlAdapter() { public void controlResized( ControlEvent e ) { if ( tree.getClientArea().width > 0 ) { int width = tree.getClientArea().width - 2 * tree.getBorderWidth(); if ( tree.getVerticalBar().isVisible() ) { width -= tree.getVerticalBar().getSize().x; } tree.getColumn( EntryEditorWidgetTableMetadata.VALUE_COLUMN_INDEX ).setWidth( width - tree.getColumn( EntryEditorWidgetTableMetadata.KEY_COLUMN_INDEX ).getWidth() ); } } } ); // setup sorter, filter and layout configuration.getSorter().connect( viewer ); configuration.getFilter().connect( viewer ); configuration.getPreferences().connect( viewer ); // Get the ValueEditorManager ValueEditorManager valueEditorManager = configuration.getValueEditorManager( viewer ); // setup providers viewer.setContentProvider( configuration.getContentProvider( this ) ); viewer.setLabelProvider( configuration.getLabelProvider( valueEditorManager, viewer ) ); // set table cell editors viewer.setCellModifier( configuration.getCellModifier( valueEditorManager ) ); CellEditor[] editors = new CellEditor[EntryEditorWidgetTableMetadata.COLUM_NAMES.length]; viewer.setCellEditors( editors ); return tree; } /** * Sets the focus to the tree viewer. */ public void setFocus() { viewer.getTree().setFocus(); } /** * {@inheritDoc} */ public void dispose() { if ( viewer != null ) { configuration.dispose(); configuration = null; if ( quickFilterWidget != null ) { quickFilterWidget.dispose(); quickFilterWidget = null; } tree.dispose(); tree = null; viewer = null; } super.dispose(); } /** * Gets the viewer. * * @return the viewer */ public TreeViewer getViewer() { return viewer; } /** * Gets the quick filter widget. * * @return the quick filter widget */ public EntryEditorWidgetQuickFilterWidget getQuickFilterWidget() { return quickFilterWidget; } /** * Enables or disables this widget. * * @param enabled true to enable this widget, false to disable this widget */ public void setEnabled( boolean enabled ) { tree.setEnabled( enabled ); } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/entryeditor/EntryEditorWidgetSorterDialog.java
plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/entryeditor/EntryEditorWidgetSorterDialog.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.ldapbrowser.common.widgets.entryeditor; import org.apache.directory.studio.common.ui.widgets.BaseWidgetUtils; import org.apache.directory.studio.ldapbrowser.common.BrowserCommonActivator; import org.apache.directory.studio.ldapbrowser.common.BrowserCommonConstants; import org.apache.directory.studio.ldapbrowser.core.BrowserCoreConstants; import org.eclipse.jface.dialogs.Dialog; import org.eclipse.jface.dialogs.IDialogConstants; import org.eclipse.jface.preference.IPreferenceStore; import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Combo; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Group; import org.eclipse.swt.widgets.Shell; /** * This class represents the dialog used to change the entry editors's default sort preferences. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class EntryEditorWidgetSorterDialog extends Dialog { /** The Constant DIALOG_TITLE. */ public static final String DIALOG_TITLE = Messages.getString( "EntryEditorWidgetSorterDialog.EntryEditorSorting" ); //$NON-NLS-1$ /** The Constant SORT_BY_NONE. */ public static final String SORT_BY_NONE = Messages.getString( "EntryEditorWidgetSorterDialog.NoDefaultSorting" ); //$NON-NLS-1$ /** The Constant SORT_BY_ATTRIBUTE. */ public static final String SORT_BY_ATTRIBUTE = Messages .getString( "EntryEditorWidgetSorterDialog.AttributeDescription" ); //$NON-NLS-1$ /** The Constant SORT_BY_VALUE. */ public static final String SORT_BY_VALUE = Messages.getString( "EntryEditorWidgetSorterDialog.Value" ); //$NON-NLS-1$ /** The preferences. */ private EntryEditorWidgetPreferences preferences; /** The object class and must attributes first button. */ private Button objectClassAndMustAttributesFirstButton; /** The operational attributes last button. */ private Button operationalAttributesLastButton; /** The sort by combo. */ private Combo sortByCombo; /** The sort acending button. */ private Button sortAcendingButton; /** The sort descending button. */ private Button sortDescendingButton; /** * Creates a new instance of EntryEditorWidgetSorterDialog. * * @param parentShell the parent shell * @param preferences the preferences */ public EntryEditorWidgetSorterDialog( Shell parentShell, EntryEditorWidgetPreferences preferences ) { super( parentShell ); this.preferences = preferences; } /** * {@inheritDoc} * * This implementation calls its super implementation and sets the dialog's title. */ protected void configureShell( Shell newShell ) { super.configureShell( newShell ); newShell.setText( DIALOG_TITLE ); } /** * {@inheritDoc} * * This implementation saves the changed settings when OK is pressed. */ protected void buttonPressed( int buttonId ) { if ( buttonId == IDialogConstants.OK_ID ) { IPreferenceStore store = BrowserCommonActivator.getDefault().getPreferenceStore(); store.setValue( BrowserCommonConstants.PREFERENCE_ENTRYEDITOR_OBJECTCLASS_AND_MUST_ATTRIBUTES_FIRST, objectClassAndMustAttributesFirstButton.getSelection() ); store.setValue( BrowserCommonConstants.PREFERENCE_ENTRYEDITOR_OPERATIONAL_ATTRIBUTES_LAST, operationalAttributesLastButton.getSelection() ); store.setValue( BrowserCommonConstants.PREFERENCE_ENTRYEDITOR_DEFAULT_SORT_ORDER, sortDescendingButton .getSelection() ? BrowserCoreConstants.SORT_ORDER_DESCENDING : BrowserCoreConstants.SORT_ORDER_ASCENDING ); store.setValue( BrowserCommonConstants.PREFERENCE_ENTRYEDITOR_DEFAULT_SORT_BY, sortByCombo .getSelectionIndex() == 2 ? BrowserCoreConstants.SORT_BY_VALUE : sortByCombo.getSelectionIndex() == 1 ? BrowserCoreConstants.SORT_BY_ATTRIBUTE_DESCRIPTION : BrowserCoreConstants.SORT_BY_NONE ); } super.buttonPressed( buttonId ); } /** * {@inheritDoc} */ protected Control createDialogArea( Composite parent ) { Composite composite = ( Composite ) super.createDialogArea( parent ); Group group = BaseWidgetUtils.createGroup( composite, Messages .getString( "EntryEditorWidgetSorterDialog.GroupAttributes" ), 1 ); //$NON-NLS-1$ GridData gd = new GridData( GridData.FILL_BOTH | GridData.GRAB_HORIZONTAL ); gd.widthHint = convertHorizontalDLUsToPixels( IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH ); group.setLayoutData( gd ); objectClassAndMustAttributesFirstButton = BaseWidgetUtils.createCheckbox( group, Messages .getString( "EntryEditorWidgetSorterDialog.ObjectClassAndMustAttributesFirst" ), 1 ); //$NON-NLS-1$ objectClassAndMustAttributesFirstButton.setSelection( preferences.isObjectClassAndMustAttributesFirst() ); operationalAttributesLastButton = BaseWidgetUtils.createCheckbox( group, Messages .getString( "EntryEditorWidgetSorterDialog.OperationalAttributesLast" ), 1 ); //$NON-NLS-1$ operationalAttributesLastButton.setSelection( preferences.isOperationalAttributesLast() ); Group sortingGroup = BaseWidgetUtils.createGroup( composite, Messages .getString( "EntryEditorWidgetSorterDialog.SortAttributes" ), 1 ); //$NON-NLS-1$ Composite sortByComposite = BaseWidgetUtils.createColumnContainer( sortingGroup, 4, 1 ); BaseWidgetUtils.createLabel( sortByComposite, Messages.getString( "EntryEditorWidgetSorterDialog.SortBy" ), 1 ); //$NON-NLS-1$ sortByCombo = BaseWidgetUtils.createReadonlyCombo( sortByComposite, new String[] { SORT_BY_NONE, SORT_BY_ATTRIBUTE, SORT_BY_VALUE }, 0, 1 ); sortByCombo.select( preferences.getDefaultSortBy() == BrowserCoreConstants.SORT_BY_VALUE ? 2 : preferences .getDefaultSortBy() == BrowserCoreConstants.SORT_BY_ATTRIBUTE_DESCRIPTION ? 1 : 0 ); sortByCombo.addSelectionListener( new SelectionAdapter() { public void widgetSelected( SelectionEvent e ) { sortAcendingButton.setEnabled( sortByCombo.getSelectionIndex() != 0 ); sortDescendingButton.setEnabled( sortByCombo.getSelectionIndex() != 0 ); } } ); sortAcendingButton = BaseWidgetUtils.createRadiobutton( sortByComposite, Messages .getString( "EntryEditorWidgetSorterDialog.Ascending" ), 1 ); //$NON-NLS-1$ sortAcendingButton .setSelection( preferences.getDefaultSortOrder() == BrowserCoreConstants.SORT_ORDER_ASCENDING ); sortAcendingButton.setEnabled( sortByCombo.getSelectionIndex() != 0 ); sortDescendingButton = BaseWidgetUtils.createRadiobutton( sortByComposite, Messages .getString( "EntryEditorWidgetSorterDialog.Descending" ), 1 ); //$NON-NLS-1$ sortDescendingButton .setSelection( preferences.getDefaultSortOrder() == BrowserCoreConstants.SORT_ORDER_DESCENDING ); sortDescendingButton.setEnabled( sortByCombo.getSelectionIndex() != 0 ); BaseWidgetUtils.createSpacer( composite, 2 ); BaseWidgetUtils.createLabel( composite, Messages.getString( "EntryEditorWidgetSorterDialog.SortTableHint" ), 1 ); //$NON-NLS-1$ applyDialogFont( composite ); return composite; } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/entryeditor/OpenSortDialogAction.java
plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/entryeditor/OpenSortDialogAction.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.ldapbrowser.common.widgets.entryeditor; import org.apache.directory.studio.ldapbrowser.common.BrowserCommonActivator; import org.apache.directory.studio.ldapbrowser.common.BrowserCommonConstants; import org.eclipse.jface.action.Action; import org.eclipse.ui.PlatformUI; public class OpenSortDialogAction extends Action { private EntryEditorWidgetPreferences preferences; public OpenSortDialogAction( EntryEditorWidgetPreferences preferences ) { setText( Messages.getString( "OpenSortDialogAction.Sorting" ) ); //$NON-NLS-1$ setToolTipText( Messages.getString( "OpenSortDialogAction.Sorting" ) ); //$NON-NLS-1$ setImageDescriptor( BrowserCommonActivator.getDefault().getImageDescriptor( BrowserCommonConstants.IMG_SORT ) ); setEnabled( true ); this.preferences = preferences; } public void run() { EntryEditorWidgetSorterDialog dlg = new EntryEditorWidgetSorterDialog( PlatformUI.getWorkbench().getDisplay() .getActiveShell(), preferences ); dlg.open(); } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/entryeditor/EntryEditorWidgetLabelProvider.java
plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/entryeditor/EntryEditorWidgetLabelProvider.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.ldapbrowser.common.widgets.entryeditor; import org.apache.directory.studio.common.ui.CommonUIConstants; import org.apache.directory.studio.common.ui.CommonUIPlugin; import org.apache.directory.studio.ldapbrowser.common.BrowserCommonActivator; import org.apache.directory.studio.ldapbrowser.common.BrowserCommonConstants; import org.apache.directory.studio.ldapbrowser.core.model.IAttribute; import org.apache.directory.studio.ldapbrowser.core.model.IValue; import org.apache.directory.studio.valueeditors.IValueEditor; import org.apache.directory.studio.valueeditors.ValueEditorManager; import org.eclipse.jface.preference.IPreferenceStore; import org.eclipse.jface.preference.PreferenceConverter; import org.eclipse.jface.viewers.IColorProvider; import org.eclipse.jface.viewers.IFontProvider; import org.eclipse.jface.viewers.ITableLabelProvider; import org.eclipse.jface.viewers.LabelProvider; import org.eclipse.jface.viewers.TreeViewer; import org.eclipse.osgi.util.NLS; import org.eclipse.swt.SWT; import org.eclipse.swt.graphics.Color; import org.eclipse.swt.graphics.Font; import org.eclipse.swt.graphics.FontData; import org.eclipse.swt.graphics.Image; import org.eclipse.swt.graphics.RGB; import org.eclipse.swt.widgets.Display; /** * The EntryEditorWidgetLabelProvider implements the label provider for * the entry editor widget. * * It provides the type value pairs for {@link IValue} objects and type plus * the number of values for {@link IAttribute} objects. It also implements * {@link IFontProvider} and {@link IColorProvider} to set the font and color * depending on whether the attribte is a must, may or operational attribute. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class EntryEditorWidgetLabelProvider extends LabelProvider implements ITableLabelProvider, IFontProvider, IColorProvider { /** The viewer */ private TreeViewer viewer; /** The value editor manager. */ private ValueEditorManager valueEditorManager; /** * Creates a new instance of EntryEditorWidgetLabelProvider. * * @param viewer the viewer * @param valueEditorManager the value editor manager */ public EntryEditorWidgetLabelProvider( TreeViewer viewer, ValueEditorManager valueEditorManager ) { this.viewer = viewer; this.valueEditorManager = valueEditorManager; } /** * {@inheritDoc} */ public void dispose() { super.dispose(); valueEditorManager = null; } /** * {@inheritDoc} */ public final String getColumnText( Object obj, int index ) { if ( obj instanceof IValue ) { IValue value = ( IValue ) obj; switch ( index ) { case EntryEditorWidgetTableMetadata.KEY_COLUMN_INDEX: return value.getAttribute().getDescription(); case EntryEditorWidgetTableMetadata.VALUE_COLUMN_INDEX: IValueEditor vp = this.valueEditorManager.getCurrentValueEditor( value ); String dv = vp.getDisplayValue( value ); return dv; default: return ""; //$NON-NLS-1$ } } else if ( obj instanceof IAttribute ) { IAttribute attribute = ( IAttribute ) obj; if ( index == EntryEditorWidgetTableMetadata.KEY_COLUMN_INDEX ) { return NLS .bind( Messages.getString( "EntryEditorWidgetLabelProvider.AttributeLabel" ), //$NON-NLS-1$ attribute.getDescription(), getNumberOfValues( attribute ) ); } else { return ""; //$NON-NLS-1$ } } else { return ""; //$NON-NLS-1$ } } /** * Gets the number of values attribute. * * @param element * @return */ private int getNumberOfValues( IAttribute attribute ) { EntryEditorWidgetContentProvider contentProvider = ( EntryEditorWidgetContentProvider ) viewer .getContentProvider(); EntryEditorWidgetFilter filter = ( EntryEditorWidgetFilter ) viewer.getFilters()[0]; int count = 0; for ( Object child : contentProvider.getChildren( attribute ) ) { if ( filter.select( viewer, attribute, child ) ) { count++; } } return count; } /** * {@inheritDoc} */ public final Image getColumnImage( Object element, int index ) { return null; } /** * {@inheritDoc} */ public Font getFont( Object element ) { IAttribute attribute = null; IValue value = null; if ( element instanceof IAttribute ) { attribute = ( IAttribute ) element; } else if ( element instanceof IValue ) { value = ( IValue ) element; attribute = value.getAttribute(); } // inconsistent attributes and values if ( value != null ) { if ( value.isEmpty() ) { FontData[] fontData = Display.getDefault().getSystemFont().getFontData(); FontData fontDataBoldItalic = new FontData( fontData[0].getName(), fontData[0].getHeight(), SWT.BOLD | SWT.ITALIC ); return BrowserCommonActivator.getDefault().getFont( new FontData[] { fontDataBoldItalic } ); } } if ( attribute != null && value == null ) { if ( !attribute.isConsistent() ) { FontData[] fontData = Display.getDefault().getSystemFont().getFontData(); FontData fontDataBoldItalic = new FontData( fontData[0].getName(), fontData[0].getHeight(), SWT.BOLD | SWT.ITALIC ); return BrowserCommonActivator.getDefault().getFont( new FontData[] { fontDataBoldItalic } ); } } // attribute type if ( attribute != null ) { if ( attribute.isObjectClassAttribute() ) { FontData[] fontData = PreferenceConverter.getFontDataArray( BrowserCommonActivator.getDefault() .getPreferenceStore(), BrowserCommonConstants.PREFERENCE_OBJECTCLASS_FONT ); return BrowserCommonActivator.getDefault().getFont( fontData ); } else if ( attribute.isMustAttribute() ) { FontData[] fontData = PreferenceConverter.getFontDataArray( BrowserCommonActivator.getDefault() .getPreferenceStore(), BrowserCommonConstants.PREFERENCE_MUSTATTRIBUTE_FONT ); return BrowserCommonActivator.getDefault().getFont( fontData ); } else if ( attribute.isOperationalAttribute() ) { FontData[] fontData = PreferenceConverter.getFontDataArray( BrowserCommonActivator.getDefault() .getPreferenceStore(), BrowserCommonConstants.PREFERENCE_OPERATIONALATTRIBUTE_FONT ); return BrowserCommonActivator.getDefault().getFont( fontData ); } else { FontData[] fontData = PreferenceConverter.getFontDataArray( BrowserCommonActivator.getDefault() .getPreferenceStore(), BrowserCommonConstants.PREFERENCE_MAYATTRIBUTE_FONT ); return BrowserCommonActivator.getDefault().getFont( fontData ); } } else { return null; } } /** * {@inheritDoc} */ public Color getForeground( Object element ) { IAttribute attribute = null; IValue value = null; if ( element instanceof IAttribute ) { attribute = ( IAttribute ) element; } else if ( element instanceof IValue ) { value = ( IValue ) element; attribute = value.getAttribute(); } // inconsistent attributes and values if ( value != null ) { if ( value.isEmpty() ) { return CommonUIPlugin.getDefault().getColor( CommonUIConstants.ERROR_COLOR ); } } if ( attribute != null && value == null ) { if ( !attribute.isConsistent() ) { return CommonUIPlugin.getDefault().getColor( CommonUIConstants.ERROR_COLOR ); } } // attribute type if ( attribute != null ) { if ( attribute.isObjectClassAttribute() ) { return getColorIfNotDefaultElseNull( BrowserCommonConstants.PREFERENCE_OBJECTCLASS_COLOR ); } else if ( attribute.isMustAttribute() ) { return getColorIfNotDefaultElseNull( BrowserCommonConstants.PREFERENCE_MUSTATTRIBUTE_COLOR ); } else if ( attribute.isOperationalAttribute() ) { return getColorIfNotDefaultElseNull( BrowserCommonConstants.PREFERENCE_OPERATIONALATTRIBUTE_COLOR ); } else { return getColorIfNotDefaultElseNull( BrowserCommonConstants.PREFERENCE_MAYATTRIBUTE_COLOR ); } } else { return null; } } private Color getColorIfNotDefaultElseNull( String color ) { BrowserCommonActivator plugin = BrowserCommonActivator.getDefault(); IPreferenceStore preferenceStore = plugin.getPreferenceStore(); if ( preferenceStore.isDefault( color ) ) { return null; } RGB rgb = PreferenceConverter.getColor( preferenceStore, color ); return plugin.getColor( rgb ); } /** * {@inheritDoc} */ public Color getBackground( Object element ) { 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/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/entryeditor/EntryEditorWidgetActionGroup.java
plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/entryeditor/EntryEditorWidgetActionGroup.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.ldapbrowser.common.widgets.entryeditor; import java.util.HashMap; import java.util.Map; import org.apache.directory.studio.ldapbrowser.common.BrowserCommonActivator; import org.apache.directory.studio.ldapbrowser.common.BrowserCommonConstants; import org.apache.directory.studio.ldapbrowser.common.actions.CopyAction; import org.apache.directory.studio.ldapbrowser.common.actions.DeleteAction; import org.apache.directory.studio.ldapbrowser.common.actions.NewValueAction; import org.apache.directory.studio.ldapbrowser.common.actions.PropertiesAction; import org.apache.directory.studio.ldapbrowser.common.actions.SelectAllAction; import org.apache.directory.studio.ldapbrowser.common.actions.ShowDecoratedValuesAction; import org.apache.directory.studio.ldapbrowser.common.actions.ValueEditorPreferencesAction; import org.apache.directory.studio.ldapbrowser.common.actions.proxy.ActionHandlerManager; import org.apache.directory.studio.ldapbrowser.common.actions.proxy.BrowserActionProxy; import org.apache.directory.studio.ldapbrowser.common.actions.proxy.EntryEditorActionProxy; import org.apache.directory.studio.ldapbrowser.core.model.AttributeHierarchy; import org.apache.directory.studio.ldapbrowser.core.model.IEntry; import org.apache.directory.studio.utils.ActionUtils; import org.apache.directory.studio.valueeditors.IValueEditor; import org.apache.directory.studio.valueeditors.ValueEditorManager; import org.eclipse.jface.action.IAction; 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.viewers.TreeViewer; import org.eclipse.ui.IActionBars; import org.eclipse.ui.actions.ActionFactory; /** * The EntryEditorWidgetActionGroup manages all actions of the entry editor widget. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class EntryEditorWidgetActionGroup implements ActionHandlerManager { /** The open sort dialog action. */ protected OpenSortDialogAction openSortDialogAction; /** The show decorated values action. */ protected ShowDecoratedValuesAction showDecoratedValuesAction; /** The show quick filter action. */ protected ShowQuickFilterAction showQuickFilterAction; /** The open default editor action. */ protected EntryEditorActionProxy openDefaultValueEditorActionProxy; /** The open best editor action. */ protected EntryEditorActionProxy openBestValueEditorActionProxy; /** The open editor actions. */ protected EntryEditorActionProxy[] openValueEditorActionProxies; /** The open value editor preferences action. */ protected ValueEditorPreferencesAction openValueEditorPreferencesAction; /** The Constant newValueAction. */ protected final static String NEW_VALUE_ACTION = "newValueAction"; //$NON-NLS-1$ /** The Constant copyAction. */ protected final static String COPY_ACTION = "copyAction"; //$NON-NLS-1$ /** The Constant pasteAction. */ protected final static String PASTE_ACTION = "pasteAction"; //$NON-NLS-1$ /** The Constant deleteAction. */ protected final static String DELETE_ACTION = "deleteAction"; //$NON-NLS-1$ /** The Constant selectAllAction. */ protected final static String SELECT_ALL_ACTION = "selectAllAction"; //$NON-NLS-1$ /** The Constant propertyDialogAction. */ protected final static String PROPERTY_DIALOG_ACTION = "propertyDialogAction"; //$NON-NLS-1$ /** The entry editor action map. */ protected Map<String, EntryEditorActionProxy> entryEditorActionMap; /** The action bars. */ protected IActionBars actionBars; /** The main widget. */ private EntryEditorWidget mainWidget; /** * Creates a new instance of EntryEditorWidgetActionGroup. * * @param mainWidget the main widget * @param configuration the configuration */ public EntryEditorWidgetActionGroup( EntryEditorWidget mainWidget, EntryEditorWidgetConfiguration configuration ) { this.mainWidget = mainWidget; entryEditorActionMap = new HashMap<String, EntryEditorActionProxy>(); TreeViewer viewer = mainWidget.getViewer(); ValueEditorManager valueEditorManager = configuration.getValueEditorManager( viewer ); openSortDialogAction = new OpenSortDialogAction( configuration.getPreferences() ); showDecoratedValuesAction = new ShowDecoratedValuesAction(); showQuickFilterAction = new ShowQuickFilterAction( mainWidget.getQuickFilterWidget() ); openBestValueEditorActionProxy = new EntryEditorActionProxy( viewer, new OpenBestEditorAction( viewer, valueEditorManager, this ) ); openDefaultValueEditorActionProxy = new EntryEditorActionProxy( viewer, new OpenDefaultEditorAction( viewer, openBestValueEditorActionProxy ) ); IValueEditor[] valueEditors = valueEditorManager.getAllValueEditors(); openValueEditorActionProxies = new EntryEditorActionProxy[valueEditors.length]; for ( int i = 0; i < openValueEditorActionProxies.length; i++ ) { openValueEditorActionProxies[i] = new EntryEditorActionProxy( viewer, new OpenEditorAction( viewer, valueEditorManager, valueEditors[i], this ) ); } openValueEditorPreferencesAction = new ValueEditorPreferencesAction(); entryEditorActionMap.put( NEW_VALUE_ACTION, new EntryEditorActionProxy( viewer, new NewValueAction() ) ); entryEditorActionMap.put( PASTE_ACTION, new EntryEditorActionProxy( viewer, new EntryEditorPasteAction() ) ); entryEditorActionMap.put( COPY_ACTION, new EntryEditorActionProxy( viewer, new CopyAction( ( BrowserActionProxy ) entryEditorActionMap.get( PASTE_ACTION ), valueEditorManager ) ) ); entryEditorActionMap.put( DELETE_ACTION, new EntryEditorActionProxy( viewer, new DeleteAction() ) ); entryEditorActionMap.put( SELECT_ALL_ACTION, new EntryEditorActionProxy( viewer, new SelectAllAction( viewer ) ) ); entryEditorActionMap.put( PROPERTY_DIALOG_ACTION, new EntryEditorActionProxy( viewer, new PropertiesAction() ) ); //viewer.addSelectionChangedListener( entryEditorListener ); } /** * Disposes this action group. */ public void dispose() { if ( mainWidget != null ) { openSortDialogAction = null; showQuickFilterAction.dispose(); showQuickFilterAction = null; showDecoratedValuesAction = null; openDefaultValueEditorActionProxy.dispose(); openDefaultValueEditorActionProxy = null; openBestValueEditorActionProxy.dispose(); openBestValueEditorActionProxy = null; for ( EntryEditorActionProxy action : openValueEditorActionProxies ) { action.dispose(); } openValueEditorPreferencesAction = null; for ( EntryEditorActionProxy action : entryEditorActionMap.values() ) { action.dispose(); } entryEditorActionMap.clear(); entryEditorActionMap = null; actionBars = null; mainWidget = null; } } /** * Enables global action handlers. * * @param actionBars the action bars */ public void enableGlobalActionHandlers( IActionBars actionBars ) { this.actionBars = actionBars; // activateGlobalActionHandlers(); } /** * Fill the tool bar. * * @param toolBarManager the tool bar manager */ public void fillToolBar( IToolBarManager toolBarManager ) { toolBarManager.add( entryEditorActionMap.get( NEW_VALUE_ACTION ) ); toolBarManager.add( new Separator() ); toolBarManager.add( entryEditorActionMap.get( DELETE_ACTION ) ); toolBarManager.add( new Separator() ); toolBarManager.add( showQuickFilterAction ); toolBarManager.update( true ); } /** * Fills the menu. * * @param menuManager the menu manager */ public void fillMenu( IMenuManager menuManager ) { menuManager.add( openSortDialogAction ); menuManager.add( showDecoratedValuesAction ); menuManager.addMenuListener( new IMenuListener() { public void menuAboutToShow( IMenuManager manager ) { showDecoratedValuesAction.setChecked( !BrowserCommonActivator.getDefault().getPreferenceStore() .getBoolean( BrowserCommonConstants.PREFERENCE_SHOW_RAW_VALUES ) ); } } ); } /** * Fills the context menu. Adds a menu listener to the given menu manager * to fill the context menu whenever it pops up. * * @param menuManager the menu manager */ public void fillContextMenu( IMenuManager menuManager ) { menuManager.setRemoveAllWhenShown( true ); menuManager.addMenuListener( new IMenuListener() { public void menuAboutToShow( IMenuManager manager ) { contextMenuAboutToShow( manager ); } } ); } /** * Fills the context menu. * * @param menuManager the menu manager */ protected void contextMenuAboutToShow( IMenuManager menuManager ) { // new menuManager.add( entryEditorActionMap.get( NEW_VALUE_ACTION ) ); menuManager.add( new Separator() ); // copy, paste, delete menuManager.add( entryEditorActionMap.get( COPY_ACTION ) ); menuManager.add( entryEditorActionMap.get( PASTE_ACTION ) ); menuManager.add( entryEditorActionMap.get( DELETE_ACTION ) ); menuManager.add( entryEditorActionMap.get( SELECT_ALL_ACTION ) ); menuManager.add( new Separator() ); // edit addEditMenu( menuManager ); menuManager.add( new Separator() ); // properties menuManager.add( entryEditorActionMap.get( PROPERTY_DIALOG_ACTION ) ); } /** * Adds the value editors to the menu. * * @param menuManager the menu manager */ protected void addEditMenu( IMenuManager menuManager ) { menuManager.add( openDefaultValueEditorActionProxy ); MenuManager editorMenuManager = new MenuManager( Messages .getString( "EntryEditorWidgetActionGroup.EditValueWith" ) ); //$NON-NLS-1$ if ( openBestValueEditorActionProxy.isEnabled() ) { editorMenuManager.add( openBestValueEditorActionProxy ); editorMenuManager.add( new Separator() ); } for ( EntryEditorActionProxy action : openValueEditorActionProxies ) { if ( action.isEnabled() && ( ( OpenEditorAction ) action.getAction() ).getValueEditor().getClass() != ( ( OpenBestEditorAction ) openBestValueEditorActionProxy .getAction() ).getBestValueEditor().getClass() ) { editorMenuManager.add( action ); } } editorMenuManager.add( new Separator() ); editorMenuManager.add( openValueEditorPreferencesAction ); menuManager.add( editorMenuManager ); } /** * Activates global action handlers. */ public void activateGlobalActionHandlers() { if ( actionBars != null ) { actionBars.setGlobalActionHandler( ActionFactory.COPY.getId(), entryEditorActionMap.get( COPY_ACTION ) ); actionBars.setGlobalActionHandler( ActionFactory.PASTE.getId(), entryEditorActionMap.get( PASTE_ACTION ) ); actionBars.setGlobalActionHandler( ActionFactory.DELETE.getId(), entryEditorActionMap.get( DELETE_ACTION ) ); actionBars.setGlobalActionHandler( ActionFactory.SELECT_ALL.getId(), entryEditorActionMap .get( SELECT_ALL_ACTION ) ); actionBars.setGlobalActionHandler( ActionFactory.PROPERTIES.getId(), entryEditorActionMap .get( PROPERTY_DIALOG_ACTION ) ); actionBars.setGlobalActionHandler( ActionFactory.FIND.getId(), showQuickFilterAction ); // IWorkbenchActionDefinitionIds.FIND_REPLACE actionBars.updateActionBars(); } else { IAction da = entryEditorActionMap.get( DELETE_ACTION ); da.setActionDefinitionId( BrowserCommonConstants.CMD_DELETE ); ActionUtils.activateActionHandler( da ); IAction ca = entryEditorActionMap.get( COPY_ACTION ); ca.setActionDefinitionId( BrowserCommonConstants.CMD_COPY ); ActionUtils.activateActionHandler( ca ); IAction pa = entryEditorActionMap.get( PASTE_ACTION ); pa.setActionDefinitionId( BrowserCommonConstants.CMD_PASTE ); ActionUtils.activateActionHandler( pa ); showQuickFilterAction.setActionDefinitionId( BrowserCommonConstants.CMD_FIND ); ActionUtils.activateActionHandler( showQuickFilterAction ); IAction pda = entryEditorActionMap.get( PROPERTY_DIALOG_ACTION ); pda.setActionDefinitionId( BrowserCommonConstants.CMD_PROPERTIES ); ActionUtils.activateActionHandler( pda ); } IAction nva = entryEditorActionMap.get( NEW_VALUE_ACTION ); ActionUtils.activateActionHandler( nva ); ActionUtils.activateActionHandler( openDefaultValueEditorActionProxy ); } /** * Deactivates global action handlers. */ public void deactivateGlobalActionHandlers() { if ( actionBars != null ) { actionBars.setGlobalActionHandler( ActionFactory.COPY.getId(), null ); actionBars.setGlobalActionHandler( ActionFactory.PASTE.getId(), null ); actionBars.setGlobalActionHandler( ActionFactory.DELETE.getId(), null ); actionBars.setGlobalActionHandler( ActionFactory.SELECT_ALL.getId(), null ); actionBars.setGlobalActionHandler( ActionFactory.FIND.getId(), null ); actionBars.setGlobalActionHandler( ActionFactory.PROPERTIES.getId(), null ); actionBars.updateActionBars(); } else { IAction ca = entryEditorActionMap.get( COPY_ACTION ); ActionUtils.deactivateActionHandler( ca ); IAction pa = entryEditorActionMap.get( PASTE_ACTION ); ActionUtils.deactivateActionHandler( pa ); IAction da = entryEditorActionMap.get( DELETE_ACTION ); ActionUtils.deactivateActionHandler( da ); ActionUtils.deactivateActionHandler( showQuickFilterAction ); IAction pda = entryEditorActionMap.get( PROPERTY_DIALOG_ACTION ); ActionUtils.deactivateActionHandler( pda ); } IAction nva = entryEditorActionMap.get( NEW_VALUE_ACTION ); ActionUtils.deactivateActionHandler( nva ); ActionUtils.deactivateActionHandler( openDefaultValueEditorActionProxy ); } /** * Gets the open default editor action. * * @return the open default editor action */ public OpenDefaultEditorAction getOpenDefaultEditorAction() { return ( OpenDefaultEditorAction ) openDefaultValueEditorActionProxy.getAction(); } /** * Sets the input. * * @param entry the input */ public void setInput( IEntry entry ) { for ( EntryEditorActionProxy action : entryEditorActionMap.values() ) { action.inputChanged( entry ); } } /** * Sets the input. * * @param attributeHierarchy the attribute hierarchy */ public void setInput( AttributeHierarchy attributeHierarchy ) { for ( EntryEditorActionProxy action : entryEditorActionMap.values() ) { action.inputChanged( attributeHierarchy ); } } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/entryeditor/AbstractOpenEditorAction.java
plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/entryeditor/AbstractOpenEditorAction.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.ldapbrowser.common.widgets.entryeditor; import org.apache.directory.studio.ldapbrowser.common.actions.BrowserAction; import org.apache.directory.studio.valueeditors.ValueEditorManager; import org.eclipse.jface.viewers.CellEditor; import org.eclipse.jface.viewers.TreeViewer; import org.eclipse.swt.SWT; import org.eclipse.swt.events.FocusEvent; import org.eclipse.swt.events.FocusListener; import org.eclipse.swt.events.KeyEvent; import org.eclipse.swt.events.KeyListener; /** * Base class for all value editor actions of the entry editor widget. * It manages activation and closing of value editors. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public abstract class AbstractOpenEditorAction extends BrowserAction implements FocusListener, KeyListener { /** The value editor manager. */ protected ValueEditorManager valueEditorManager; /** The viewer. */ protected TreeViewer viewer; /** The cell editor. */ private CellEditor cellEditor; /** The actionGroup. */ protected EntryEditorWidgetActionGroup actionGroup; /** * Creates a new instance of AbstractOpenEditorAction. * * @param viewer the viewer * @param valueEditorManager the value editor manager */ protected AbstractOpenEditorAction( TreeViewer viewer, ValueEditorManager valueEditorManager, EntryEditorWidgetActionGroup actionGroup ) { this.viewer = viewer; this.valueEditorManager = valueEditorManager; this.actionGroup = actionGroup; } /** * {@inheritDoc} */ public void dispose() { valueEditorManager = null; viewer = null; cellEditor = null; super.dispose(); } /** * Gets the cell editor. * * @return the cell editor */ public CellEditor getCellEditor() { return cellEditor; } /** * Sets the cell editor. * * @param cellEditor the cell editor */ public void setCellEditor( CellEditor cellEditor ) { this.cellEditor = cellEditor; } /** * {@inheritDoc} */ public void run() { activateEditor(); } /** * Activates the editor. */ private void activateEditor() { if ( !viewer.isCellEditorActive() && ( getSelectedValues().length == 1 ) && ( getSelectedAttributes().length == 0 ) && viewer.getCellModifier().canModify( getSelectedValues()[0], EntryEditorWidgetTableMetadata.VALUE_COLUMN_NAME ) ) { // disable action handlers actionGroup.deactivateGlobalActionHandlers(); // set cell editor to viewer viewer.getCellEditors()[EntryEditorWidgetTableMetadata.VALUE_COLUMN_INDEX] = cellEditor; // add listener for end of editing if ( cellEditor.getControl() != null ) { cellEditor.getControl().addFocusListener( this ); cellEditor.getControl().addKeyListener( this ); } // start editing viewer.editElement( getSelectedValues()[0], EntryEditorWidgetTableMetadata.VALUE_COLUMN_INDEX ); if ( !viewer.isCellEditorActive() ) { editorClosed(); } } else { valueEditorManager.setUserSelectedValueEditor( null ); } } /** * Editor closed. */ private void editorClosed() { // remove cell editors from viewer to prevent auto-editing for ( int i = 0; i < viewer.getCellEditors().length; i++ ) { viewer.getCellEditors()[i] = null; } // remove listener if ( cellEditor.getControl() != null ) { cellEditor.getControl().removeFocusListener( this ); cellEditor.getControl().removeKeyListener( this ); } // reset custom value editor and set selection to notify all // actions to update their enabled state. valueEditorManager.setUserSelectedValueEditor( null ); viewer.setSelection( viewer.getSelection() ); // enable action handlers actionGroup.activateGlobalActionHandlers(); } /** * {@inheritDoc} */ public void focusGained( FocusEvent e ) { } /** * {@inheritDoc} */ public void focusLost( FocusEvent e ) { editorClosed(); } /** * {@inheritDoc} */ public void keyPressed( KeyEvent e ) { if ( e.character == SWT.ESC && e.stateMask == SWT.NONE ) { e.doit = false; } } /** * {@inheritDoc} */ public void keyReleased( KeyEvent 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/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/entryeditor/ShowQuickFilterAction.java
plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/entryeditor/ShowQuickFilterAction.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.ldapbrowser.common.widgets.entryeditor; import org.apache.directory.studio.ldapbrowser.common.BrowserCommonActivator; import org.apache.directory.studio.ldapbrowser.common.BrowserCommonConstants; import org.eclipse.jface.action.Action; import org.eclipse.ui.texteditor.IWorkbenchActionDefinitionIds; /** * This action shows/hides the instant search. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class ShowQuickFilterAction extends Action { /** The Constant SHOW_QUICKFILTER_DIALOGSETTING_KEY. */ public static final String SHOW_QUICKFILTER_DIALOGSETTING_KEY = ShowQuickFilterAction.class.getName() + ".showQuickFilter"; //$NON-NLS-1$ /** The quick filter widget. */ private EntryEditorWidgetQuickFilterWidget quickFilterWidget; /** * Creates a new instance of ShowQuickFilterAction. * * @param quickFilterWidget the quick filter widget */ public ShowQuickFilterAction( EntryEditorWidgetQuickFilterWidget quickFilterWidget ) { super( Messages.getString( "ShowQuickFilterAction.ShowQuickFilter" ), AS_CHECK_BOX ); //$NON-NLS-1$ setToolTipText( Messages.getString( "ShowQuickFilterAction.ShowQuickFilter" ) ); //$NON-NLS-1$ setImageDescriptor( BrowserCommonActivator.getDefault().getImageDescriptor( BrowserCommonConstants.IMG_FILTER ) ); setActionDefinitionId( IWorkbenchActionDefinitionIds.FIND_REPLACE ); setEnabled( true ); this.quickFilterWidget = quickFilterWidget; if ( BrowserCommonActivator.getDefault().getDialogSettings().get( SHOW_QUICKFILTER_DIALOGSETTING_KEY ) == null ) { BrowserCommonActivator.getDefault().getDialogSettings().put( SHOW_QUICKFILTER_DIALOGSETTING_KEY, false ); } // call the super implementation here because the local implementation // does nothing. super.setChecked( BrowserCommonActivator.getDefault().getDialogSettings().getBoolean( SHOW_QUICKFILTER_DIALOGSETTING_KEY ) ); quickFilterWidget.setActive( isChecked() ); } /** * {@inheritDoc} * * This implementation toggles the checked state and * activates or deactivates the quick filter accordingly. */ public void run() { boolean checked = isChecked(); super.setChecked( !checked ); BrowserCommonActivator.getDefault().getDialogSettings().put( SHOW_QUICKFILTER_DIALOGSETTING_KEY, isChecked() ); if ( quickFilterWidget != null ) { quickFilterWidget.setActive( isChecked() ); } } /** * {@inheritDoc} * * This implementation does nothing. Toggling of the checked state is done within the run() method. */ public void setChecked( boolean checked ) { } /** * Disposes this action. */ public void dispose() { quickFilterWidget = 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/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/entryeditor/EntryEditorWidgetTableMetadata.java
plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/entryeditor/EntryEditorWidgetTableMetadata.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.ldapbrowser.common.widgets.entryeditor; /** * The EntryEditorWidgetTableMetadata class contains some constants used * by the entry editor widget. * Final reference -> class shouldn't be extended * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public final class EntryEditorWidgetTableMetadata { /** * 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 EntryEditorWidgetTableMetadata() { } /** The Constant KEY_COLUMN_INDEX. */ public static final int KEY_COLUMN_INDEX = 0; /** The Constant VALUE_COLUMN_INDEX. */ public static final int VALUE_COLUMN_INDEX = 1; /** The Constant KEY_COLUMN_NAME. */ public static final String KEY_COLUMN_NAME = Messages .getString( "EntryEditorWidgetTableMetadata.AttributeDescription" ); //$NON-NLS-1$ /** The Constant VALUE_COLUMN_NAME. */ public static final String VALUE_COLUMN_NAME = Messages.getString( "EntryEditorWidgetTableMetadata.Value" ); //$NON-NLS-1$ /** The Constant COLUM_NAMES. */ public static final String[] COLUM_NAMES = { KEY_COLUMN_NAME, VALUE_COLUMN_NAME }; }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/entryeditor/EntryEditorWidgetCellModifier.java
plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/entryeditor/EntryEditorWidgetCellModifier.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.ldapbrowser.common.widgets.entryeditor; import org.apache.directory.studio.ldapbrowser.core.model.IValue; import org.apache.directory.studio.ldapbrowser.core.utils.CompoundModification; import org.apache.directory.studio.valueeditors.ValueEditorManager; import org.eclipse.jface.viewers.ICellModifier; import org.eclipse.swt.widgets.Item; /** * The EntryEditorWidgetCellModifier implements the {@link ICellModifier} interface * for the entry editor widget. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class EntryEditorWidgetCellModifier implements ICellModifier { /** The value editor manager. */ private ValueEditorManager valueEditorManager; /** * Creates a new instance of EntryEditorWidgetCellModifier. * * @param valueEditorManager */ public EntryEditorWidgetCellModifier( ValueEditorManager valueEditorManager ) { this.valueEditorManager = valueEditorManager; } /** * Disposes this cell modifier. */ public void dispose() { valueEditorManager = null; } /** * {@inheritDoc} */ public boolean canModify( Object element, String property ) { if ( ( element instanceof IValue ) && ( valueEditorManager != null ) ) { IValue attributeValue = ( IValue ) element; if ( EntryEditorWidgetTableMetadata.KEY_COLUMN_NAME.equals( property ) ) { return false; } if ( EntryEditorWidgetTableMetadata.VALUE_COLUMN_NAME.equals( property ) ) { return valueEditorManager.getCurrentValueEditor( attributeValue ).hasValue( attributeValue ); } } return false; } /** * {@inheritDoc} */ public Object getValue( Object element, String property ) { if ( ( element instanceof IValue ) && ( valueEditorManager != null ) ) { IValue attributeValue = ( IValue ) element; Object returnValue; if ( EntryEditorWidgetTableMetadata.KEY_COLUMN_NAME.equals( property ) ) { returnValue = attributeValue.getAttribute().getDescription(); } else if ( EntryEditorWidgetTableMetadata.VALUE_COLUMN_NAME.equals( property ) ) { returnValue = this.valueEditorManager.getCurrentValueEditor( attributeValue ).getRawValue( attributeValue ); } else { returnValue = ""; //$NON-NLS-1$ } return returnValue; } else { return null; } } /** * {@inheritDoc} */ public void modify( Object element, String property, Object newRawValue ) { if ( element instanceof Item ) { element = ( ( Item ) element ).getData(); } if ( ( newRawValue != null ) && ( element instanceof IValue ) && ( valueEditorManager != null ) ) { IValue oldValue = ( IValue ) element; if ( EntryEditorWidgetTableMetadata.VALUE_COLUMN_NAME.equals( property ) ) { new CompoundModification().modifyValue( oldValue, newRawValue ); } } } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/entryeditor/OpenBestEditorAction.java
plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/entryeditor/OpenBestEditorAction.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.ldapbrowser.common.widgets.entryeditor; import java.util.Collection; import org.apache.directory.api.ldap.model.schema.AttributeType; import org.apache.directory.studio.ldapbrowser.core.BrowserCoreConstants; import org.apache.directory.studio.ldapbrowser.core.model.IAttribute; import org.apache.directory.studio.ldapbrowser.core.model.IEntry; import org.apache.directory.studio.ldapbrowser.core.model.IValue; import org.apache.directory.studio.ldapbrowser.core.model.schema.SchemaUtils; import org.apache.directory.studio.valueeditors.IValueEditor; import org.apache.directory.studio.valueeditors.ValueEditorManager; import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.jface.viewers.TreeViewer; import org.eclipse.osgi.util.NLS; /** * The OpenBestEditorAction is used to edit a value with the best value editor. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class OpenBestEditorAction extends AbstractOpenEditorAction { /** The best value editor. */ private IValueEditor bestValueEditor; /** * Creates a new instance of OpenBestEditorAction. * * @param viewer the viewer * @param valueEditorManager the value editor manager * @param actionGroup the action group */ public OpenBestEditorAction( TreeViewer viewer, ValueEditorManager valueEditorManager, EntryEditorWidgetActionGroup actionGroup ) { super( viewer, valueEditorManager, actionGroup ); } /** * Gets the best value editor. * * @return the best value editor */ public IValueEditor getBestValueEditor() { return this.bestValueEditor; } /** * {@inheritDoc} */ public void dispose() { bestValueEditor = null; super.dispose(); } /** * {@inheritDoc} */ public String getCommandId() { return null; } /** * {@inheritDoc} */ public ImageDescriptor getImageDescriptor() { return isEnabled() ? bestValueEditor.getValueEditorImageDescriptor() : null; } /** * {@inheritDoc} */ public String getText() { if ( isEnabled() ) { return bestValueEditor.getValueEditorName(); } else { return null; } } /** * {@inheritDoc} */ public boolean isEnabled() { if ( getSelectedValues().length == 1 && getSelectedAttributes().length == 0 && viewer.getCellModifier().canModify( getSelectedValues()[0], EntryEditorWidgetTableMetadata.VALUE_COLUMN_NAME ) ) { // update value editor bestValueEditor = valueEditorManager.getCurrentValueEditor( getSelectedValues()[0] ); setCellEditor( bestValueEditor.getCellEditor() ); return true; } else { bestValueEditor = null; return false; } } @Override public void run() { boolean ok = true; if ( ( getSelectedValues().length == 1 ) && ( getSelectedAttributes().length == 0 ) ) { IValue value = getSelectedValues()[0]; StringBuffer message = new StringBuffer(); IAttribute attribute = value.getAttribute(); String description = attribute.getDescription(); AttributeType atd = attribute.getAttributeTypeDescription(); if ( value.isEmpty() ) { // validate single-valued attributes if ( ( attribute.getValueSize() > 1 ) && atd.isSingleValued() ) { message.append( NLS.bind( Messages.getString( "OpenBestEditorAction.ValueSingleValued" ), description ) );//$NON-NLS-1$ message.append( BrowserCoreConstants.LINE_SEPARATOR ); message.append( BrowserCoreConstants.LINE_SEPARATOR ); } // validate if value is allowed IEntry entry = attribute.getEntry(); Collection<AttributeType> allAtds = SchemaUtils.getAllAttributeTypeDescriptions( entry ); if ( !allAtds.contains( atd ) ) { message.append( NLS.bind( Messages.getString( "OpenBestEditorAction.AttributeNotInSubSchema" ), description ) );//$NON-NLS-1$ message.append( BrowserCoreConstants.LINE_SEPARATOR ); message.append( BrowserCoreConstants.LINE_SEPARATOR ); } } // validate non-modifiable attributes if ( !SchemaUtils.isModifiable( atd ) ) { message.append( NLS.bind( Messages.getString( "OpenBestEditorAction.ValueNotModifiable" ), description ) );//$NON-NLS-1$ message.append( BrowserCoreConstants.LINE_SEPARATOR ); message.append( BrowserCoreConstants.LINE_SEPARATOR ); } // validate modification of Rdn if ( value.isRdnPart() && ( getCellEditor() != valueEditorManager.getRenameValueEditor() ) ) { message.append( NLS.bind( Messages.getString( "OpenBestEditorAction.ValueIsRdnPart" ), description ) );//$NON-NLS-1$ message.append( BrowserCoreConstants.LINE_SEPARATOR ); message.append( BrowserCoreConstants.LINE_SEPARATOR ); } if ( message.length() > 0 ) { if ( value.isEmpty() ) { message.append( Messages.getString( "OpenBestEditorAction.NewValueQuestion" ) ); //$NON-NLS-1$ } else { message.append( Messages.getString( "OpenBestEditorAction.EditValueQuestion" ) ); //$NON-NLS-1$ } ok = MessageDialog.openConfirm( getShell(), getText(), message.toString() ); } if ( ok ) { super.run(); } else { if ( value.isEmpty() ) { attribute.deleteEmptyValue(); } } } } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/entryeditor/EntryEditorWidgetPreferences.java
plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/entryeditor/EntryEditorWidgetPreferences.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.ldapbrowser.common.widgets.entryeditor; import org.apache.directory.studio.ldapbrowser.common.BrowserCommonActivator; import org.apache.directory.studio.ldapbrowser.common.BrowserCommonConstants; import org.apache.directory.studio.ldapbrowser.core.BrowserCoreConstants; import org.eclipse.jface.viewers.TreeViewer; import org.eclipse.jface.viewers.Viewer; /** * This class is a wrapper for the preferences of the entry editor widget. * The preferences we handle for the EntryEditor are the following : * <ul> * <li>PREFERENCE_ENTRYEDITOR_ENABLE_FOLDING : </li> * <li>PREFERENCE_ENTRYEDITOR_FOLDING_THRESHOLD : </li> * <li>PREFERENCE_ENTRYEDITOR_AUTO_EXPAND_FOLDED_ATTRIBUTES</li> * <li>PREFERENCE_ENTRYEDITOR_OBJECTCLASS_AND_MUST_ATTRIBUTES_FIRST : put the ObjectClass and the MUST attributes first</li> * <li>PREFERENCE_ENTRYEDITOR_OPERATIONAL_ATTRIBUTES_LAST : show the operational attributes at the end</li> * <li>PREFERENCE_ENTRYEDITOR_DEFAULT_SORT_BY: sort either by the attribute or by the values</li> * <li>PREFERENCE_ENTRYEDITOR_DEFAULT_SORT_ORDER : defines the sort order (none, ascending or descending)</li> * </ul> * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class EntryEditorWidgetPreferences { /** The viewer. */ protected Viewer viewer; /** * Creates a new instance of EntryEditorWidgetPreferences. */ public EntryEditorWidgetPreferences() { } /** * Connects this preferences with the given viewer. * * @param viewer the viewer */ public void connect( TreeViewer viewer ) { this.viewer = viewer; } /** * Disposes this preferences. */ public void dispose() { viewer = null; } /** * Checks if folding is enabled. * * @return true, if folding is enabled */ public boolean isUseFolding() { return BrowserCommonActivator.getDefault().getPreferenceStore().getBoolean( BrowserCommonConstants.PREFERENCE_ENTRYEDITOR_ENABLE_FOLDING ); } /** * Gets the folding threshold. * * @return the folding threshold */ public int getFoldingThreshold() { return BrowserCommonActivator.getDefault().getPreferenceStore().getInt( BrowserCommonConstants.PREFERENCE_ENTRYEDITOR_FOLDING_THRESHOLD ); } /** * Checks if is auto expand folded attributes. * * @return true, if is auto expand folded attributes */ public boolean isAutoExpandFoldedAttributes() { return BrowserCommonActivator.getDefault().getPreferenceStore().getBoolean( BrowserCommonConstants.PREFERENCE_ENTRYEDITOR_AUTO_EXPAND_FOLDED_ATTRIBUTES ); } /** * Checks if object class and must attributes should be * grouped before may attributes. * * @return true, if object class and must attributes first */ public boolean isObjectClassAndMustAttributesFirst() { return BrowserCommonActivator.getDefault().getPreferenceStore().getBoolean( BrowserCommonConstants.PREFERENCE_ENTRYEDITOR_OBJECTCLASS_AND_MUST_ATTRIBUTES_FIRST ); } /** * Checks if operational attributes should be grouped after may attributes. * * @return true, if operational attributes last */ public boolean isOperationalAttributesLast() { return BrowserCommonActivator.getDefault().getPreferenceStore().getBoolean( BrowserCommonConstants.PREFERENCE_ENTRYEDITOR_OPERATIONAL_ATTRIBUTES_LAST ); } /** * Gets the default sort property, one of * {@link BrowserCoreConstants#SORT_BY_ATTRIBUTE_DESCRIPTION} or * {@link BrowserCoreConstants#SORT_BY_VALUE}. * * @return the default sort property */ public int getDefaultSortBy() { return BrowserCommonActivator.getDefault().getPreferenceStore().getInt( BrowserCommonConstants.PREFERENCE_ENTRYEDITOR_DEFAULT_SORT_BY ); } /** * Gets the default sort property, one of * {@link BrowserCoreConstants#SORT_ORDER_NONE}, * {@link BrowserCoreConstants#SORT_ORDER_ASCENDING} or * {@link BrowserCoreConstants#SORT_ORDER_DESCENDING}. * * @return the default sort property */ public int getDefaultSortOrder() { return BrowserCommonActivator.getDefault().getPreferenceStore().getInt( BrowserCommonConstants.PREFERENCE_ENTRYEDITOR_DEFAULT_SORT_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/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/entryeditor/OpenEditorAction.java
plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/entryeditor/OpenEditorAction.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.ldapbrowser.common.widgets.entryeditor; import java.util.Arrays; import org.apache.directory.studio.valueeditors.IValueEditor; import org.apache.directory.studio.valueeditors.ValueEditorManager; import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.jface.viewers.TreeViewer; /** * The OpenEditorAction is used to edit a value with a specific value editor. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class OpenEditorAction extends AbstractOpenEditorAction { /** The specific value editor. */ private IValueEditor valueEditor; /** * Creates a new instance of OpenEditorAction. * * @param viewer the viewer * @param valueEditorManager the value editor manager * @param valueEditor the specific value editor * @param actionGroup the action group */ public OpenEditorAction( TreeViewer viewer, ValueEditorManager valueEditorManager, IValueEditor valueEditor, EntryEditorWidgetActionGroup actionGroup ) { super( viewer, valueEditorManager, actionGroup ); setCellEditor( valueEditor.getCellEditor() ); this.valueEditor = valueEditor; } /** * Gets the value editor. * * @return the value editor */ public IValueEditor getValueEditor() { return valueEditor; } /** * {@inheritDoc} */ public void run() { // ensure that the specific value editor is activated valueEditorManager.setUserSelectedValueEditor( valueEditor ); super.run(); } /** * {@inheritDoc} */ public void dispose() { valueEditor = null; super.dispose(); } /** * {@inheritDoc} */ public String getCommandId() { return null; } /** * {@inheritDoc} */ public ImageDescriptor getImageDescriptor() { return valueEditor.getValueEditorImageDescriptor(); } /** * {@inheritDoc} */ public String getText() { return valueEditor.getValueEditorName(); } /** * {@inheritDoc} */ public boolean isEnabled() { if ( getSelectedValues().length == 1 && getSelectedAttributes().length == 0 ) // && viewer.getCellModifier().canModify( getSelectedValues()[0], // EntryEditorWidgetTableMetadata.VALUE_COLUMN_NAME ) { IValueEditor[] alternativeVps = valueEditorManager.getAlternativeValueEditors( getSelectedValues()[0] ); return Arrays.asList( alternativeVps ).contains( valueEditor ) && valueEditor.getRawValue( getSelectedValues()[0] ) != null; } else { 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/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/entryeditor/Messages.java
plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/entryeditor/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.ldapbrowser.common.widgets.entryeditor; 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/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/entryeditor/EntryEditorWidgetActionGroupWithAttribute.java
plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/entryeditor/EntryEditorWidgetActionGroupWithAttribute.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.ldapbrowser.common.widgets.entryeditor; import org.apache.directory.studio.ldapbrowser.common.actions.DeleteAllValuesAction; import org.apache.directory.studio.ldapbrowser.common.actions.NewAttributeAction; import org.apache.directory.studio.ldapbrowser.common.actions.proxy.EntryEditorActionProxy; import org.apache.directory.studio.utils.ActionUtils; import org.eclipse.jface.action.IAction; 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.viewers.TreeViewer; /** * This class manages all the actions of the attribute page of the new entry wizard. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class EntryEditorWidgetActionGroupWithAttribute extends EntryEditorWidgetActionGroup { /** The Constant editAttributeDescriptionAction. */ private static final String EDIT_ATTRIBUTE_DESCRIPTION_ACTION = "editAttributeDescriptionAction"; //$NON-NLS-1$ /** The Constant newAttributeAction. */ private static final String NEW_ATTRIBUTE_ACTION = "newAttributeAction"; //$NON-NLS-1$ /** The Constant deleteAllValuesAction. */ private static final String DELETE_ALL_VALUES_ACTION = "deleteAllValuesAction"; //$NON-NLS-1$ /** * * Creates a new instance of NewEntryAttributesWizardPageActionGroup. * * @param mainWidget * @param configuration */ public EntryEditorWidgetActionGroupWithAttribute( EntryEditorWidget mainWidget, EntryEditorWidgetConfiguration configuration ) { super( mainWidget, configuration ); TreeViewer viewer = mainWidget.getViewer(); entryEditorActionMap.put( EDIT_ATTRIBUTE_DESCRIPTION_ACTION, new EntryEditorActionProxy( viewer, new EditAttributeDescriptionAction( viewer ) ) ); entryEditorActionMap.put( NEW_ATTRIBUTE_ACTION, new EntryEditorActionProxy( viewer, new NewAttributeAction() ) ); entryEditorActionMap.put( DELETE_ALL_VALUES_ACTION, new EntryEditorActionProxy( viewer, new DeleteAllValuesAction() ) ); } /** * {@inheritDoc} */ public void fillToolBar( IToolBarManager toolBarManager ) { toolBarManager.add( ( IAction ) entryEditorActionMap.get( NEW_VALUE_ACTION ) ); toolBarManager.add( ( IAction ) entryEditorActionMap.get( NEW_ATTRIBUTE_ACTION ) ); toolBarManager.add( new Separator() ); toolBarManager.add( ( IAction ) this.entryEditorActionMap.get( DELETE_ACTION ) ); toolBarManager.add( ( IAction ) this.entryEditorActionMap.get( DELETE_ALL_VALUES_ACTION ) ); toolBarManager.add( new Separator() ); toolBarManager.add( this.showQuickFilterAction ); toolBarManager.update( true ); } /** * {@inheritDoc} */ protected void contextMenuAboutToShow( IMenuManager menuManager ) { // new menuManager.add( ( IAction ) entryEditorActionMap.get( NEW_ATTRIBUTE_ACTION ) ); menuManager.add( ( IAction ) entryEditorActionMap.get( NEW_VALUE_ACTION ) ); menuManager.add( new Separator() ); // copy, paste, delete menuManager.add( ( IAction ) entryEditorActionMap.get( COPY_ACTION ) ); menuManager.add( ( IAction ) entryEditorActionMap.get( PASTE_ACTION ) ); menuManager.add( ( IAction ) entryEditorActionMap.get( DELETE_ACTION ) ); menuManager.add( ( IAction ) entryEditorActionMap.get( SELECT_ALL_ACTION ) ); MenuManager copyMenuManager = new MenuManager( Messages .getString( "EntryEditorWidgetActionGroupWithAttribute.Advanced" ) ); //$NON-NLS-1$ copyMenuManager.add( ( IAction ) entryEditorActionMap.get( DELETE_ALL_VALUES_ACTION ) ); menuManager.add( copyMenuManager ); menuManager.add( new Separator() ); // edit menuManager.add( ( IAction ) entryEditorActionMap.get( EDIT_ATTRIBUTE_DESCRIPTION_ACTION ) ); super.addEditMenu( menuManager ); menuManager.add( new Separator() ); // properties menuManager.add( ( IAction ) entryEditorActionMap.get( PROPERTY_DIALOG_ACTION ) ); } /** * {@inheritDoc} */ public void activateGlobalActionHandlers() { super.activateGlobalActionHandlers(); IAction naa = ( IAction ) entryEditorActionMap.get( NEW_ATTRIBUTE_ACTION ); ActionUtils.activateActionHandler( naa ); IAction eada = ( IAction ) entryEditorActionMap.get( EDIT_ATTRIBUTE_DESCRIPTION_ACTION ); ActionUtils.activateActionHandler( eada ); } /** * {@inheritDoc} */ public void deactivateGlobalActionHandlers() { super.deactivateGlobalActionHandlers(); IAction naa = ( IAction ) entryEditorActionMap.get( NEW_ATTRIBUTE_ACTION ); ActionUtils.deactivateActionHandler( naa ); IAction eada = ( IAction ) entryEditorActionMap.get( EDIT_ATTRIBUTE_DESCRIPTION_ACTION ); ActionUtils.deactivateActionHandler( eada ); } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/entryeditor/EntryEditorWidgetFilter.java
plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/entryeditor/EntryEditorWidgetFilter.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.ldapbrowser.common.widgets.entryeditor; import org.apache.directory.api.util.Strings; import org.apache.directory.studio.ldapbrowser.common.BrowserCommonActivator; import org.apache.directory.studio.ldapbrowser.core.model.IAttribute; import org.apache.directory.studio.ldapbrowser.core.model.IValue; import org.eclipse.jface.viewers.TreeViewer; import org.eclipse.jface.viewers.Viewer; import org.eclipse.jface.viewers.ViewerFilter; /** * The EntryEditorWidgetFilter implements the filter for * the entry editor widget. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class EntryEditorWidgetFilter extends ViewerFilter { /** The viewer to filter. */ protected TreeViewer viewer; /** The quick filter attribute. */ protected String quickFilterAttribute; /** The quick filter value. */ protected String quickFilterValue; /** * Creates a new instance of EntryEditorWidgetFilter. */ public EntryEditorWidgetFilter() { quickFilterAttribute = ""; //$NON-NLS-1$ quickFilterValue = ""; //$NON-NLS-1$ } /** * Connects this filter with the given viewer. * * @param viewer the viewer */ public void connect( TreeViewer viewer ) { this.viewer = viewer; viewer.addFilter( this ); } /** * {@inheritDoc} */ public boolean select( Viewer viewer, Object parentElement, Object element ) { if ( element instanceof IAttribute ) { // check if one of the values goes through the quick filter IValue[] values = ( ( IAttribute ) element).getValues(); for ( IValue value : values ) { if ( goesThroughQuickFilter( value ) ) { return true; } } return false; } else if ( element instanceof IValue ) { // check quick filter return goesThroughQuickFilter( ( IValue ) element ); } return true; } /** * Checks if the given value goes through quick filter. * * @param value the value * * @return true, if goes through quick filter */ private boolean goesThroughQuickFilter( IValue value ) { // filter attribute description if ( !Strings.isEmpty( quickFilterAttribute ) ) { if ( value.getAttribute().getDescription().toUpperCase().indexOf( quickFilterAttribute.toUpperCase() ) == -1 ) { return false; } } // filter value if ( !Strings.isEmpty( quickFilterValue ) ) { if ( value.isString() && value.getStringValue().toUpperCase().indexOf( quickFilterValue.toUpperCase() ) == -1 ) { return false; } else if ( value.isBinary() ) { return false; } } return true; } /** * Disposes this filter. */ public void dispose() { viewer = null; } /** * Gets the quick filter attribute. * * @return the quick filter attribute */ public String getQuickFilterAttribute() { return quickFilterAttribute; } /** * Sets the quick filter attribute. * * @param quickFilterAttribute the quick filter attribute */ public void setQuickFilterAttribute( String quickFilterAttribute ) { if ( !this.quickFilterAttribute.equals( quickFilterAttribute ) ) { String oldValue = this.quickFilterAttribute; this.quickFilterAttribute = quickFilterAttribute; BrowserCommonActivator.getDefault().getPreferenceStore() .firePropertyChangeEvent( "QuickFilterAttributeChanged", oldValue, quickFilterAttribute ); //$NON-NLS-1$ } } /** * Gets the quick filter value. * * @return the quick filter value */ public String getQuickFilterValue() { return quickFilterValue; } /** * Sets the quick filter value. * * @param quickFilterValue the quick filter value */ public void setQuickFilterValue( String quickFilterValue ) { if ( !this.quickFilterValue.equals( quickFilterValue ) ) { String oldValue = this.quickFilterValue; this.quickFilterValue = quickFilterValue; BrowserCommonActivator.getDefault().getPreferenceStore() .firePropertyChangeEvent( "QuickFilterValueChanged", oldValue, quickFilterAttribute ); //$NON-NLS-1$ } } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/entryeditor/EntryEditorWidgetConfiguration.java
plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/entryeditor/EntryEditorWidgetConfiguration.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.ldapbrowser.common.widgets.entryeditor; import org.apache.directory.studio.valueeditors.ValueEditorManager; import org.eclipse.jface.viewers.TreeViewer; /** * The EntryEditorWidgetConfiguration contains the content provider, * label provider, sorter, filter, the context menu manager and the * preferences for the entry editor widget. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class EntryEditorWidgetConfiguration { /** The disposed flag */ private boolean disposed = false; /** The sorter. */ protected EntryEditorWidgetSorter sorter; /** The filter. */ protected EntryEditorWidgetFilter filter; /** The preferences. */ protected EntryEditorWidgetPreferences preferences; /** The content provider. */ protected EntryEditorWidgetContentProvider contentProvider; /** The label provider. */ protected EntryEditorWidgetLabelProvider labelProvider; /** The cell modifier. */ protected EntryEditorWidgetCellModifier cellModifier; /** The value editor manager. */ protected ValueEditorManager valueEditorManager; /** * Creates a new instance of EntryEditorWidgetConfiguration. */ public EntryEditorWidgetConfiguration() { } /** * Disposes this configuration. */ public void dispose() { if ( !disposed ) { if ( sorter != null ) { sorter.dispose(); sorter = null; } if ( filter != null ) { filter.dispose(); filter = null; } if ( preferences != null ) { preferences.dispose(); preferences = null; } if ( contentProvider != null ) { contentProvider.dispose(); contentProvider = null; } if ( labelProvider != null ) { labelProvider.dispose(); labelProvider = null; } if ( cellModifier != null ) { cellModifier.dispose(); cellModifier = null; } if ( valueEditorManager != null ) { valueEditorManager.dispose(); valueEditorManager = null; } disposed = true; } } /** * Gets the content provider. * * @param mainWidget the main widget * * @return the content provider */ public EntryEditorWidgetContentProvider getContentProvider( EntryEditorWidget mainWidget ) { if ( contentProvider == null ) { contentProvider = new EntryEditorWidgetContentProvider( getPreferences(), mainWidget ); } return contentProvider; } /** * Gets the label provider. * * @param viewer the viewer * * @return the label provider */ public EntryEditorWidgetLabelProvider getLabelProvider( ValueEditorManager valueEditorManager, TreeViewer viewer ) { if ( labelProvider == null ) { labelProvider = new EntryEditorWidgetLabelProvider( viewer, valueEditorManager ); } return labelProvider; } /** * Gets the cell modifier. * * @param viewer the viewer * * @return the cell modifier */ public EntryEditorWidgetCellModifier getCellModifier( ValueEditorManager valueEditorManager ) { if ( cellModifier == null ) { cellModifier = new EntryEditorWidgetCellModifier( valueEditorManager ); } return cellModifier; } /** * Gets the value editor manager. * * @param viewer the viewer * * @return the value editor manager */ public ValueEditorManager getValueEditorManager( TreeViewer viewer ) { if ( valueEditorManager == null ) { valueEditorManager = new ValueEditorManager( viewer.getTree(), false, false ); } return valueEditorManager; } /** * Gets the sorter. * * @return the sorter */ public EntryEditorWidgetSorter getSorter() { if ( sorter == null ) { sorter = new EntryEditorWidgetSorter( getPreferences() ); } return sorter; } /** * Gets the filter. * * @return the filter */ public EntryEditorWidgetFilter getFilter() { if ( filter == null ) { filter = new EntryEditorWidgetFilter(); } return filter; } /** * Gets the preferences. * * @return the preferences */ public EntryEditorWidgetPreferences getPreferences() { if ( preferences == null ) { preferences = new EntryEditorWidgetPreferences(); } return preferences; } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/entryeditor/EntryEditorWidgetContentProvider.java
plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/entryeditor/EntryEditorWidgetContentProvider.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.ldapbrowser.common.widgets.entryeditor; import java.util.ArrayList; import java.util.List; import org.apache.directory.studio.ldapbrowser.core.jobs.InitializeAttributesRunnable; import org.apache.directory.studio.ldapbrowser.core.jobs.StudioBrowserJob; import org.apache.directory.studio.ldapbrowser.core.model.AttributeHierarchy; import org.apache.directory.studio.ldapbrowser.core.model.IAttribute; import org.apache.directory.studio.ldapbrowser.core.model.IEntry; import org.apache.directory.studio.ldapbrowser.core.model.IValue; import org.eclipse.jface.viewers.ITreeContentProvider; import org.eclipse.jface.viewers.Viewer; /** * The EntryEditorWidgetContentProvider implements the content provider for * the entry editor widget. It accepts an {@link IEntry} or an * {@link AttributeHierarchy} as input. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class EntryEditorWidgetContentProvider implements ITreeContentProvider { /** The preferences. */ protected EntryEditorWidgetPreferences preferences; /** The main widget. */ protected EntryEditorWidget mainWidget; /** * Creates a new instance of EntryEditorWidgetContentProvider. * * @param preferences the preferences * @param mainWidget the main widget */ public EntryEditorWidgetContentProvider( EntryEditorWidgetPreferences preferences, EntryEditorWidget mainWidget ) { this.preferences = preferences; this.mainWidget = mainWidget; } /** * {@inheritDoc} * * This implementations updates the enabled state and the info text. */ public void inputChanged( Viewer viewer, Object oldInput, Object newInput ) { if ( mainWidget != null ) { String dn = ""; //$NON-NLS-1$ boolean enabled = true; if ( newInput instanceof IEntry ) { IEntry entry = ( IEntry ) newInput; dn = Messages.getString( "EntryEditorWidgetContentProvider.DNLabel" ) + entry.getDn().getName(); //$NON-NLS-1$ } else if ( newInput instanceof AttributeHierarchy ) { AttributeHierarchy ah = ( AttributeHierarchy ) newInput; dn = Messages.getString( "EntryEditorWidgetContentProvider.DNLabel" ) + ah.getAttribute().getEntry().getDn().getName(); //$NON-NLS-1$ } else { dn = Messages.getString( "EntryEditorWidgetContentProvider.NoEntrySelected" ); //$NON-NLS-1$ enabled = false; } if ( ( mainWidget.getInfoText() != null ) && !mainWidget.getInfoText().isDisposed() ) { mainWidget.getInfoText().setText( dn ); } if ( mainWidget.getQuickFilterWidget() != null ) { mainWidget.getQuickFilterWidget().setEnabled( enabled ); } if ( mainWidget.getViewer() != null && !mainWidget.getViewer().getTree().isDisposed() ) { mainWidget.getViewer().getTree().setEnabled( enabled ); } } } /** * {@inheritDoc} */ public void dispose() { preferences = null; mainWidget = null; } /** * {@inheritDoc} */ public Object[] getElements( Object inputElement ) { if ( inputElement instanceof IEntry ) { IEntry entry = ( IEntry ) inputElement; if ( !entry.isAttributesInitialized() ) { InitializeAttributesRunnable runnable = new InitializeAttributesRunnable( entry ); StudioBrowserJob job = new StudioBrowserJob( runnable ); job.execute(); return new Object[0]; } else { IAttribute[] attributes = entry.getAttributes(); Object[] values = getValues( attributes ); return values; } } else if ( inputElement instanceof AttributeHierarchy ) { AttributeHierarchy ah = ( AttributeHierarchy ) inputElement; IAttribute[] attributes = ah.getAttributes(); Object[] values = getValues( attributes ); return values; } else { return new Object[0]; } } /** * Gets the values of the given attributes. * * @param attributes the attributes * * @return the values */ private Object[] getValues( IAttribute[] attributes ) { List<Object> valueList = new ArrayList<Object>(); if ( attributes != null ) { for ( IAttribute attribute : attributes ) { IValue[] values = attribute.getValues(); if (( preferences == null ) || !preferences.isUseFolding() || ( values.length <= preferences.getFoldingThreshold() ) ) { for ( IValue value : values ) { valueList.add( value ); } } else { // if folding threshold is exceeded then return the attribute itself valueList.add( attribute ); } } } return valueList.toArray(); } /** * {@inheritDoc} */ public Object[] getChildren( Object parentElement ) { if ( parentElement instanceof IAttribute ) { IAttribute attribute = ( IAttribute ) parentElement; IValue[] values = attribute.getValues(); return values; } return null; } /** * {@inheritDoc} */ public Object getParent( Object element ) { if ( element instanceof IValue ) { return ( ( IValue ) element ).getAttribute(); } return null; } /** * {@inheritDoc} */ public boolean hasChildren( Object element ) { return ( element instanceof IAttribute ); } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/entryeditor/OpenDefaultEditorAction.java
plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/entryeditor/OpenDefaultEditorAction.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.ldapbrowser.common.widgets.entryeditor; import org.apache.directory.studio.ldapbrowser.common.BrowserCommonConstants; import org.apache.directory.studio.ldapbrowser.common.actions.BrowserAction; import org.apache.directory.studio.ldapbrowser.common.actions.proxy.EntryEditorActionProxy; import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.jface.viewers.TreeViewer; /** * The OpenBestEditorAction is used to edit a value with the default value editor. * This is either the best value editor or in case of an Rdn attribute the rename * action is invoked. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class OpenDefaultEditorAction extends BrowserAction { /** The best value editor proxy. */ private EntryEditorActionProxy bestValueEditorProxy; /** * Creates a new instance of OpenDefaultEditorAction. * * @param viewer the viewer * @param bestValueEditorProxy the best value editor proxy * @param enableRenameAction true to enable rename action */ public OpenDefaultEditorAction( TreeViewer viewer, EntryEditorActionProxy bestValueEditorProxy ) { this.bestValueEditorProxy = bestValueEditorProxy; } /** * @see org.apache.directory.studio.ldapbrowser.common.actions.BrowserAction#dispose() */ public void dispose() { bestValueEditorProxy = null; super.dispose(); } /** * @see org.apache.directory.studio.ldapbrowser.common.actions.BrowserAction#getCommandId() */ public String getCommandId() { return BrowserCommonConstants.ACTION_ID_EDIT_VALUE; } /** * @see org.apache.directory.studio.ldapbrowser.common.actions.BrowserAction#getImageDescriptor() */ public ImageDescriptor getImageDescriptor() { if ( bestValueEditorProxy != null ) { return bestValueEditorProxy.getImageDescriptor(); } else { return null; } } /** * @see org.apache.directory.studio.ldapbrowser.common.actions.BrowserAction#getText() */ public String getText() { return Messages.getString( "OpenDefaultEditorAction.EditValue" ); //$NON-NLS-1$ } /** * @see org.apache.directory.studio.ldapbrowser.common.actions.BrowserAction#isEnabled() */ public boolean isEnabled() { if ( bestValueEditorProxy != null ) { return bestValueEditorProxy.isEnabled(); } else { return false; } } /** * @see org.apache.directory.studio.ldapbrowser.common.actions.BrowserAction#run() */ public void run() { if ( bestValueEditorProxy != null && bestValueEditorProxy.isEnabled() ) { bestValueEditorProxy.run(); } } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/entryeditor/EditAttributeDescriptionAction.java
plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/entryeditor/EditAttributeDescriptionAction.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.ldapbrowser.common.widgets.entryeditor; import org.apache.directory.studio.ldapbrowser.common.BrowserCommonConstants; import org.apache.directory.studio.ldapbrowser.common.actions.BrowserAction; import org.apache.directory.studio.ldapbrowser.common.actions.DeleteAction; import org.apache.directory.studio.ldapbrowser.common.actions.proxy.EntryEditorActionProxy; import org.apache.directory.studio.ldapbrowser.common.wizards.AttributeWizard; import org.apache.directory.studio.ldapbrowser.core.model.IValue; import org.apache.directory.studio.ldapbrowser.core.utils.CompoundModification; import org.eclipse.jface.dialogs.Dialog; import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.jface.viewers.Viewer; import org.eclipse.jface.wizard.WizardDialog; import org.eclipse.swt.widgets.Display; /** * This Action is used to edit an attribute description within the entry edtitor. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class EditAttributeDescriptionAction extends BrowserAction { /** To avoid duplicate implementations of the isEnabled() code we use a delete action */ private EntryEditorActionProxy deleteActionProxy; /** * Creates a new instance of EditAttributeDescriptionAction. * * @param viewer the viewer */ public EditAttributeDescriptionAction( Viewer viewer ) { deleteActionProxy = new EntryEditorActionProxy( viewer, new DeleteAction() ); } /** * {@inheritDoc} */ @Override public String getCommandId() { return BrowserCommonConstants.ACTION_ID_EDIT_ATTRIBUTE_DESCRIPTION; } /** * {@inheritDoc} */ @Override public ImageDescriptor getImageDescriptor() { return null; } /** * {@inheritDoc} */ @Override public String getText() { return Messages.getString( "EditAttributeDescriptionAction.EditAttributeDescription" ); //$NON-NLS-1$ } /** * {@inheritDoc} */ @Override public boolean isEnabled() { return deleteActionProxy.getAction().isEnabled(); } /** * {@inheritDoc} */ @Override public void run() { if ( getSelectedAttributes().length == 1 ) { renameValues( getSelectedAttributes()[0].getValues() ); } else if ( getSelectedValues().length > 0 ) { renameValues( getSelectedValues() ); } } /** * Rename the given values. * * @param values the values */ private void renameValues( final IValue[] values ) { AttributeWizard wizard = new AttributeWizard( Messages .getString( "EditAttributeDescriptionAction.EditAttributeDescription" ), true, false, //$NON-NLS-1$ values[0].getAttribute().getDescription(), values[0].getAttribute().getEntry() ); WizardDialog dialog = new WizardDialog( Display.getDefault().getActiveShell(), wizard ); dialog.setBlockOnOpen( true ); dialog.create(); if ( dialog.open() == Dialog.OK ) { String newAttributeDescription = wizard.getAttributeDescription(); new CompoundModification().renameValues( values, newAttributeDescription ); } } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/entryeditor/EntryEditorWidgetUniversalListener.java
plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/entryeditor/EntryEditorWidgetUniversalListener.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.ldapbrowser.common.widgets.entryeditor; import org.apache.directory.studio.ldapbrowser.common.BrowserCommonActivator; import org.apache.directory.studio.ldapbrowser.common.actions.BrowserSelectionUtils; import org.apache.directory.studio.ldapbrowser.core.events.BulkModificationEvent; import org.apache.directory.studio.ldapbrowser.core.events.EmptyValueAddedEvent; import org.apache.directory.studio.ldapbrowser.core.events.EmptyValueDeletedEvent; import org.apache.directory.studio.ldapbrowser.core.events.EntryModificationEvent; import org.apache.directory.studio.ldapbrowser.core.events.EntryUpdateListener; import org.apache.directory.studio.ldapbrowser.core.events.EventRegistry; import org.apache.directory.studio.ldapbrowser.core.events.ValueAddedEvent; import org.apache.directory.studio.ldapbrowser.core.events.ValueDeletedEvent; import org.apache.directory.studio.ldapbrowser.core.events.ValueModifiedEvent; import org.apache.directory.studio.ldapbrowser.core.events.ValueRenamedEvent; import org.apache.directory.studio.ldapbrowser.core.model.AttributeHierarchy; import org.apache.directory.studio.ldapbrowser.core.model.IAttribute; import org.apache.directory.studio.ldapbrowser.core.model.IEntry; import org.apache.directory.studio.ldapbrowser.core.model.IValue; import org.eclipse.jface.util.IPropertyChangeListener; import org.eclipse.jface.util.PropertyChangeEvent; import org.eclipse.jface.viewers.StructuredSelection; import org.eclipse.jface.viewers.TreeViewer; import org.eclipse.swt.SWT; import org.eclipse.swt.events.MouseAdapter; import org.eclipse.swt.events.MouseEvent; import org.eclipse.swt.events.MouseListener; import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.events.SelectionListener; import org.eclipse.swt.events.TraverseEvent; import org.eclipse.swt.events.TraverseListener; /** * The EntryEditorWidgetUniversalListener manages all events for the entry editor widget. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class EntryEditorWidgetUniversalListener implements EntryUpdateListener { /** The tree viewer */ protected TreeViewer viewer; /** The configuration. */ protected EntryEditorWidgetConfiguration configuration; /** The action group. */ protected EntryEditorWidgetActionGroup actionGroup; /** The action used to start the default value editor */ protected OpenDefaultEditorAction startEditAction; /** This listener starts the value editor when pressing enter */ protected SelectionListener viewerSelectionListener = new SelectionAdapter() { /** * {@inheritDoc} */ public void widgetSelected( SelectionEvent e ) { } /** * {@inheritDoc} * * This implementation starts the value editor. */ public void widgetDefaultSelected( SelectionEvent e ) { if ( startEditAction.isEnabled() ) { startEditAction.run(); } } }; /** This listener starts the value editor or expands/collapses the selected attribute */ protected MouseListener viewerMouseListener = new MouseAdapter() { /** * {@inheritDoc} * * This implementation starts the value editor or expands/collapses the selected attribute. */ public void mouseDoubleClick( MouseEvent e ) { IAttribute[] attributes = BrowserSelectionUtils.getAttributes( viewer.getSelection() ); IValue[] values = BrowserSelectionUtils.getValues( viewer.getSelection() ); if ( ( attributes.length == 1 ) && ( values.length == 0 ) ) { if ( viewer.getExpandedState( attributes[0] ) ) { viewer.collapseToLevel( attributes[0], 1 ); } else { viewer.expandToLevel( attributes[0], 1 ); } } } /** * {@inheritDoc} */ public void mouseDown( MouseEvent e ) { } /** * {@inheritDoc} */ public void mouseUp( MouseEvent e ) { } }; /** This listener updates the viewer if an property (e.g. is operational attributes visible) has been changed */ protected IPropertyChangeListener propertyChangeListener = new IPropertyChangeListener() { public void propertyChange( PropertyChangeEvent event ) { if ( viewer != null ) { viewer.refresh(); } } }; /** * Creates a new instance of EntryEditorWidgetUniversalListener. * * @param treeViewer the tree viewer * @param configuration the configuration * @param actionGroup the action group * @param startEditAction the action used to start the default value editor */ public EntryEditorWidgetUniversalListener( TreeViewer treeViewer, EntryEditorWidgetConfiguration configuration, EntryEditorWidgetActionGroup actionGroup, OpenDefaultEditorAction startEditAction ) { this.startEditAction = startEditAction; this.viewer = treeViewer; this.configuration = configuration; this.actionGroup = actionGroup; // register listeners viewer.getTree().addSelectionListener( viewerSelectionListener ); viewer.getTree().addMouseListener( viewerMouseListener ); EventRegistry.addEntryUpdateListener( this, BrowserCommonActivator.getDefault().getEventRunner() ); BrowserCommonActivator.getDefault().getPreferenceStore().addPropertyChangeListener( propertyChangeListener ); // Don't invoke Finish' or 'OK' button when pressing 'Enter' in wizard or dialog viewer.getTree().addTraverseListener( new TraverseListener() { public void keyTraversed( TraverseEvent e ) { if ( e.detail == SWT.TRAVERSE_RETURN ) { e.doit = false; } } } ); } /** * Disposes this universal listener. */ public void dispose() { if ( viewer != null ) { EventRegistry.removeEntryUpdateListener( this ); BrowserCommonActivator.getDefault().getPreferenceStore().removePropertyChangeListener( propertyChangeListener ); startEditAction = null; viewer = null; configuration = null; actionGroup = null; } } /** * {@inheritDoc} * * This implementation refreshes the viewer and selects a value depending * on the event. */ public void entryUpdated( EntryModificationEvent event ) { if ( ( viewer == null ) || ( viewer.getTree() == null ) || viewer.getTree().isDisposed() || ( viewer.getInput() == null ) || ( ( event.getModifiedEntry() != viewer.getInput() ) && !( event instanceof BulkModificationEvent ) ) ) { return; } // force closing of cell editors if ( viewer.isCellEditorActive() ) { viewer.cancelEditing(); } // refresh viewer.refresh(); // selection value if ( event instanceof ValueAddedEvent ) { // select the vadded value ValueAddedEvent vaEvent = ( ValueAddedEvent ) event; viewer.setSelection( new StructuredSelection( vaEvent.getAddedValue() ), true ); viewer.refresh(); } else if ( event instanceof ValueDeletedEvent ) { // select another value of the deleted attribute ValueDeletedEvent vdEvent = ( ValueDeletedEvent ) event; if ( viewer.getSelection().isEmpty() && vdEvent.getDeletedValue().getAttribute().getValueSize() > 0 ) { viewer.setSelection( new StructuredSelection( vdEvent.getDeletedValue().getAttribute().getValues()[0] ), true ); } } else if ( event instanceof EmptyValueAddedEvent ) { EmptyValueAddedEvent evaEvent = ( EmptyValueAddedEvent ) event; // select the added value and start editing viewer.setSelection( new StructuredSelection( evaEvent.getAddedValue() ), true ); if ( startEditAction.isEnabled() && viewer.getControl().isFocusControl() ) { startEditAction.run(); } } else if ( event instanceof EmptyValueDeletedEvent ) { // select another value of the deleted attribute EmptyValueDeletedEvent evdEvent = ( EmptyValueDeletedEvent ) event; if ( viewer.getSelection().isEmpty() && ( evdEvent.getDeletedValue().getAttribute().getValueSize() > 0 ) ) { viewer.setSelection( new StructuredSelection( evdEvent.getDeletedValue().getAttribute().getValues()[0] ), true ); } } else if ( event instanceof ValueModifiedEvent ) { // select the modified value ValueModifiedEvent vmEvent = ( ValueModifiedEvent ) event; viewer.setSelection( new StructuredSelection( vmEvent.getNewValue() ), true ); } else if ( event instanceof ValueRenamedEvent ) { // select the renamed value ValueRenamedEvent vrEvent = ( ValueRenamedEvent ) event; viewer.setSelection( new StructuredSelection( vrEvent.getNewValue() ), true ); } } /** * Sets the input to the viewer. * * @param entry the entry input */ public void setInput( IEntry entry ) { // if ( entry != viewer.getInput() ) { viewer.setInput( entry ); actionGroup.setInput( entry ); expandFoldedAttributes(); } } /** * Sets the input to the viewer. * * @param attributeHierarchy the attribute hierarchy */ public void setInput( AttributeHierarchy attributeHierarchy ) { if ( attributeHierarchy != viewer.getInput() ) { viewer.setInput( attributeHierarchy ); actionGroup.setInput( attributeHierarchy ); expandFoldedAttributes(); } } /** * Expands folded attributes if the appropriate preference is set. */ protected void expandFoldedAttributes() { if ( configuration.getPreferences().isAutoExpandFoldedAttributes() ) { viewer.expandAll(); } } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/entryeditor/EntryEditorWidgetQuickFilterWidget.java
plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/entryeditor/EntryEditorWidgetQuickFilterWidget.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.ldapbrowser.common.widgets.entryeditor; import org.apache.directory.api.util.Strings; import org.apache.directory.studio.common.ui.widgets.BaseWidgetUtils; import org.apache.directory.studio.ldapbrowser.common.BrowserCommonActivator; import org.apache.directory.studio.ldapbrowser.common.BrowserCommonConstants; 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.Text; /** * The EntryEditorWidgetQuickFilterWidget implements an instant search * for the entry editor widget. It contains separate search fields for * attribute type and/or value, plus a Clear button : * <pre> * +----------------------------------------------------------------+ * | [(attribute)] [(Value) ] (X Clear) | * +----------------------------------------------------------------+ * </pre> * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class EntryEditorWidgetQuickFilterWidget { /** The filter to propagate the entered filter phrases. */ private EntryEditorWidgetFilter filter; /** The entry editor widget. */ private EntryEditorWidget entryEditorWidget; /** The parent, used to create the composite. */ private Composite parent; /** The outer composite. */ private Composite composite; /** The inner composite, it is created/destroyed when showing/hiding the quick filter. */ private Composite innerComposite; /** The quick filter attribute text. */ private Text quickFilterAttributeText; /** The quick filter value text. */ private Text quickFilterValueText; /** The clear quick filter button. */ private Button clearQuickFilterButton; /** * The Listener that reacts on any text entered into the quick Attribute filter text widget */ private ModifyListener quickFilterAttributeTextListener = new ModifyListener() { public void modifyText( ModifyEvent e ) { filter.setQuickFilterAttribute( quickFilterAttributeText.getText() ); clearQuickFilterButton.setEnabled( !Strings.isEmpty( quickFilterAttributeText.getText() ) //$NON-NLS-1$ || !Strings.isEmpty( quickFilterValueText.getText() ) ); //$NON-NLS-1$ } }; /** * The Listener that reacts on any text entered into the quick Value filter text widget */ private ModifyListener quickFilterValueTextListener = new ModifyListener() { public void modifyText( ModifyEvent e ) { filter.setQuickFilterValue( quickFilterValueText.getText() ); clearQuickFilterButton.setEnabled( !Strings.isEmpty( quickFilterAttributeText.getText() ) //$NON-NLS-1$ || !Strings.isEmpty( quickFilterValueText.getText() ) ); //$NON-NLS-1$ } }; /** * The listener associated with teh Clear button. It will reset the attribute and value Texts */ public SelectionAdapter clearQuickFilterButtonListener = new SelectionAdapter() { public void widgetSelected( SelectionEvent e ) { quickFilterAttributeText.setText( "" ); //$NON-NLS-1$ quickFilterValueText.setText( "" ); //$NON-NLS-1$ } }; /** * Creates a new instance of EntryEditorWidgetQuickFilterWidget. * * @param filter the filter * @param entryEditorWidget the entry editor widget */ public EntryEditorWidgetQuickFilterWidget( EntryEditorWidgetFilter filter, EntryEditorWidget entryEditorWidget ) { this.filter = filter; this.entryEditorWidget = entryEditorWidget; } /** * Creates the outer composite. * <pre> * +----------------------------------------------------------+ * | | * +----------------------------------------------------------+ * </pre> * * @param parent the parent */ public void createComposite( Composite parent ) { this.parent = parent; composite = BaseWidgetUtils.createColumnContainer( parent, 1, 1 ); GridLayout gl = new GridLayout(); gl.marginHeight = 2; gl.marginWidth = 2; composite.setLayout( gl ); // Setting the default width and height of the composite to 0 GridData compositeGridData = new GridData( SWT.NONE, SWT.NONE, false, false ); compositeGridData.heightHint = 0; compositeGridData.widthHint = 0; composite.setLayoutData( compositeGridData ); innerComposite = null; } /** * Creates the inner composite with its input fields. * <pre> * [ ] [ ] (X) * </pre> */ private void createFilterView() { // Reseting the layout of the composite to be displayed correctly GridData compositeGridData = new GridData( SWT.FILL, SWT.NONE, true, false ); composite.setLayoutData( compositeGridData ); innerComposite = BaseWidgetUtils.createColumnContainer( composite, 3, 1 ); // The QuickFilterAttribute Text quickFilterAttributeText = new Text( innerComposite, SWT.BORDER ); quickFilterAttributeText.setLayoutData( new GridData( 200 - 14, SWT.DEFAULT ) ); quickFilterAttributeText.addModifyListener( quickFilterAttributeTextListener ); // The QuickFilterValue Text quickFilterValueText = new Text( innerComposite, SWT.BORDER ); quickFilterValueText.setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) ); quickFilterValueText.addModifyListener( quickFilterValueTextListener ); // The QuickFilter Button clearQuickFilterButton = new Button( innerComposite, SWT.PUSH ); clearQuickFilterButton.setToolTipText( Messages .getString( "EntryEditorWidgetQuickFilterWidget.ClearQuickFilter" ) ); //$NON-NLS-1$ clearQuickFilterButton.setImage( BrowserCommonActivator.getDefault() .getImage( BrowserCommonConstants.IMG_CLEAR ) ); clearQuickFilterButton.setEnabled( false ); clearQuickFilterButton.addSelectionListener( clearQuickFilterButtonListener ); setEnabled( composite.isEnabled() ); composite.layout( true, true ); parent.layout( true, true ); } /** * Destroys the inner widget. */ private void destroy() { // Reseting the layout of the composite with a width and height set to 0 GridData compositeGridData = new GridData( SWT.NONE, SWT.NONE, false, false ); compositeGridData.heightHint = 0; compositeGridData.widthHint = 0; composite.setLayoutData( compositeGridData ); quickFilterAttributeText.setText( "" ); //$NON-NLS-1$ quickFilterValueText.setText( "" ); //$NON-NLS-1$ innerComposite.dispose(); innerComposite = null; composite.layout( true, true ); parent.layout( true, true ); } /** * Disposes this widget. */ public void dispose() { if ( filter != null ) { quickFilterAttributeText = null; quickFilterValueText = null; clearQuickFilterButton = null; innerComposite = null; composite.dispose(); composite = null; parent = null; filter = null; } } /** * Enables or disables this quick filter widget. * * @param enabled true to enable this quick filter widget, false to disable it */ public void setEnabled( boolean enabled ) { if ( ( composite != null ) && !composite.isDisposed() ) { composite.setEnabled( enabled ); } if ( ( innerComposite != null ) && !innerComposite.isDisposed() ) { innerComposite.setEnabled( enabled ); quickFilterAttributeText.setEnabled( enabled ); quickFilterValueText.setEnabled( enabled ); clearQuickFilterButton.setEnabled( enabled ); } } /** * Activates or deactivates this quick filter widget. * * @param visible true to create this quick filter widget, false to destroy it */ public void setActive( boolean visible ) { if ( visible && ( innerComposite == null ) && ( composite != null ) ) { createFilterView(); quickFilterAttributeText.setFocus(); } else if ( !visible && ( innerComposite != null ) && ( composite != null ) ) { destroy(); entryEditorWidget.getViewer().getTree().setFocus(); } } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/connection/BrowserParameterPage.java
plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/connection/BrowserParameterPage.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.ldapbrowser.common.widgets.connection; import java.util.List; import org.apache.commons.lang3.StringUtils; import org.apache.directory.api.ldap.model.name.Dn; import org.apache.directory.api.ldap.model.url.LdapUrl; import org.apache.directory.api.ldap.model.url.LdapUrl.Extension; import org.apache.directory.studio.common.ui.widgets.BaseWidgetUtils; import org.apache.directory.studio.connection.core.Connection; import org.apache.directory.studio.connection.core.ConnectionParameter; import org.apache.directory.studio.connection.ui.AbstractConnectionParameterPage; import org.apache.directory.studio.connection.ui.RunnableContextRunner; import org.apache.directory.studio.ldapbrowser.common.widgets.search.AliasesDereferencingWidget; import org.apache.directory.studio.ldapbrowser.common.widgets.search.LimitWidget; import org.apache.directory.studio.ldapbrowser.common.widgets.search.ReferralsHandlingWidget; import org.apache.directory.studio.ldapbrowser.core.jobs.FetchBaseDNsRunnable; import org.apache.directory.studio.ldapbrowser.core.model.IBrowserConnection; import org.apache.directory.studio.ldapbrowser.core.model.impl.BrowserConnection; import org.eclipse.core.runtime.IStatus; import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.swt.SWT; import org.eclipse.swt.events.ModifyEvent; import org.eclipse.swt.events.ModifyListener; import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.events.VerifyEvent; import org.eclipse.swt.events.VerifyListener; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Combo; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Group; import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Text; /** * The BrowserParameterPage is used the edit the browser specific parameters of a * connection. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class BrowserParameterPage extends AbstractConnectionParameterPage { private static final String X_BASE_DN = "X-BASE-Dn"; //$NON-NLS-1$ private static final String X_COUNT_LIMIT = "X-COUNT-LIMIT"; //$NON-NLS-1$ private static final String X_TIME_LIMIT = "X-TIME-LIMIT"; //$NON-NLS-1$ private static final String X_ALIAS_HANDLING = "X-ALIAS-HANDLING"; //$NON-NLS-1$ private static final String X_ALIAS_HANDLING_FINDING = "FINDING"; //$NON-NLS-1$ private static final String X_ALIAS_HANDLING_SEARCHING = "SEARCHING"; //$NON-NLS-1$ private static final String X_ALIAS_HANDLING_NEVER = "NEVER"; //$NON-NLS-1$ private static final String X_REFERRAL_HANDLING = "X-REFERRAL-HANDLING"; //$NON-NLS-1$ private static final String X_REFERRAL_HANDLING_IGNORE = "IGNORE"; //$NON-NLS-1$ private static final String X_REFERRAL_HANDLING_FOLLOW = "FOLLOW"; //$NON-NLS-1$ private static final String X_MANAGE_DSA_IT = "X-MANAGE-DSA-IT"; //$NON-NLS-1$ private static final String X_FETCH_SUBENTRIES = "X-FETCH-SUBENTRIES"; //$NON-NLS-1$ private static final String X_FETCH_OPERATIONAL_ATTRIBUTES = "X-FETCH-OPERATIONAL-ATTRIBUTES"; //$NON-NLS-1$ private static final String X_PAGED_SEARCH = "X-PAGED-SEARCH"; //$NON-NLS-1$ private static final String X_PAGED_SEARCH_SIZE = "X-PAGED-SEARCH-SIZE"; //$NON-NLS-1$ private static final String X_PAGED_SEARCH_SCROLL_MODE = "X-PAGED-SEARCH-SCROLL-MODE"; //$NON-NLS-1$ /** The checkbox to fetch the base Dn's from namingContexts whenever opening the connection */ private Button autoFetchBaseDnsButton; /** The button to fetch the base Dn's from namingContexts attribute */ private Button fetchBaseDnsButton; /** The combo that displays the fetched base Dn's */ private Combo baseDNCombo; /** The widget with the count and time limits */ private LimitWidget limitWidget; /** The widget to select the alias dereferencing method */ private AliasesDereferencingWidget aliasesDereferencingWidget; /** The widget to select the referrals handling method */ private ReferralsHandlingWidget referralsHandlingWidget; /** The ManageDsaIT control button. */ private Button manageDsaItButton; /** The fetch subentries button. */ private Button fetchSubentriesButton; /** The paged search button. */ private Button pagedSearchButton; /** The paged search size label. */ private Label pagedSearchSizeLabel; /** The paged search size text. */ private Text pagedSearchSizeText; /** The paged search scroll mode button. */ private Button pagedSearchScrollModeButton; /** The fetch operational attributes button. */ private Button fetchOperationalAttributesButton; /** * Creates a new instance of BrowserParameterPage. */ public BrowserParameterPage() { } /** * Returns true if base Dn's should be fetched * whenever opening the connection. * * @return true, if base Dn's should be fetched */ private boolean isAutoFetchBaseDns() { return autoFetchBaseDnsButton.getSelection(); } /** * Gets the base Dn. * * @return the base Dn */ private String getBaseDN() { return isAutoFetchBaseDns() ? null : baseDNCombo.getText(); } /** * Gets the count limit. * * @return the count limit */ private int getCountLimit() { return limitWidget.getCountLimit(); } /** * Gets the time limit. * * @return the time limit */ private int getTimeLimit() { return limitWidget.getTimeLimit(); } /** * Gets the aliases dereferencing method. * * @return the aliases dereferencing method */ private Connection.AliasDereferencingMethod getAliasesDereferencingMethod() { return aliasesDereferencingWidget.getAliasesDereferencingMethod(); } /** * Gets the referrals handling method. * * @return the referrals handling method */ private Connection.ReferralHandlingMethod getReferralsHandlingMethod() { return referralsHandlingWidget.getReferralsHandlingMethod(); } /** * Returns true if ManageDsaIT control should be used * while browsing. * * @return true, if ManageDsaIT control should be used */ private boolean manageDsaIT() { return manageDsaItButton.getSelection(); } /** * Returns true if subentries should be fetched * while browsing. * * @return true, if subentries should be fetched */ private boolean isFetchSubentries() { return fetchSubentriesButton.getSelection(); } /** * Returns true if operational attributes should be fetched * while browsing. * * @return true, if operational attributes should be fetched */ private boolean isFetchOperationalAttributes() { return fetchOperationalAttributesButton.getSelection(); } /** * Returns true if paged search should be used * while browsing. * * @return true, if paged search should be used */ private boolean isPagedSearch() { return pagedSearchButton.getSelection(); } /** * Gets the paged search size. * * @return the paged search size */ private int getPagedSearchSize() { int pageSize; try { pageSize = Integer.valueOf( pagedSearchSizeText.getText() ); } catch ( NumberFormatException e ) { pageSize = 100; } return pageSize; } /** * Returns true if scroll mode should be used * for paged search. * * @return true, if scroll mode should be used */ private boolean isPagedSearchScrollMode() { return pagedSearchScrollModeButton.getSelection(); } /** * Gets a temporary connection with all connection parameter * entered in this page. * * @return a test connection */ private Connection getTestConnection() { ConnectionParameter cp = connectionParameterPageModifyListener.getTestConnectionParameters(); Connection conn = new Connection( cp ); return conn; } /** * @see org.apache.directory.studio.connection.ui.AbstractConnectionParameterPage#createComposite(org.eclipse.swt.widgets.Composite) */ protected void createComposite( Composite parent ) { addBaseDNInput( parent ); addLimitInput( parent ); addControlInput( parent ); addFeaturesInput( parent ); } /** * Adds the base Dn input. * * @param parent the parent */ private void addBaseDNInput( Composite parent ) { Composite composite = BaseWidgetUtils.createColumnContainer( parent, 1, 1 ); Group group = BaseWidgetUtils.createGroup( composite, Messages.getString( "BrowserParameterPage.BaseDNGroup" ), 1 ); //$NON-NLS-1$ Composite groupComposite = BaseWidgetUtils.createColumnContainer( group, 3, 1 ); GridData gd; autoFetchBaseDnsButton = BaseWidgetUtils.createCheckbox( groupComposite, Messages .getString( "BrowserParameterPage.GetBaseDNsFromRootDSE" ), 2 ); //$NON-NLS-1$ autoFetchBaseDnsButton.setSelection( true ); fetchBaseDnsButton = new Button( groupComposite, SWT.PUSH ); fetchBaseDnsButton.setText( Messages.getString( "BrowserParameterPage.FetchBaseDNs" ) ); //$NON-NLS-1$ fetchBaseDnsButton.setEnabled( true ); gd = new GridData(); gd.horizontalAlignment = SWT.RIGHT; fetchBaseDnsButton.setLayoutData( gd ); BaseWidgetUtils.createLabel( groupComposite, Messages.getString( "BrowserParameterPage.BaseDN" ), 1 ); //$NON-NLS-1$ baseDNCombo = BaseWidgetUtils.createCombo( groupComposite, new String[0], 0, 2 ); } /** * Adds the control input. * * @param parent the parent */ private void addControlInput( Composite parent ) { Composite composite = BaseWidgetUtils.createColumnContainer( parent, 1, 1 ); Group group = BaseWidgetUtils.createGroup( composite, Messages.getString( "BrowserParameterPage.Controls" ), 1 ); //$NON-NLS-1$ Composite groupComposite = BaseWidgetUtils.createColumnContainer( group, 1, 1 ); // ManageDsaIT control manageDsaItButton = BaseWidgetUtils.createCheckbox( groupComposite, Messages .getString( "BrowserParameterPage.ManageDsaItWhileBrowsing" ), 1 ); //$NON-NLS-1$ manageDsaItButton.setToolTipText( Messages.getString( "BrowserParameterPage.ManageDsaItWhileBrowsingTooltip" ) ); //$NON-NLS-1$ manageDsaItButton.setSelection( false ); // fetch subentries control fetchSubentriesButton = BaseWidgetUtils.createCheckbox( groupComposite, Messages .getString( "BrowserParameterPage.FetchSubentriesWhileBrowsing" ), 1 ); //$NON-NLS-1$ fetchSubentriesButton.setToolTipText( Messages .getString( "BrowserParameterPage.FetchSubentriesWhileBrowsingTooltip" ) ); //$NON-NLS-1$ fetchSubentriesButton.setSelection( false ); // paged search control Composite sprcComposite = BaseWidgetUtils.createColumnContainer( groupComposite, 4, 1 ); pagedSearchButton = BaseWidgetUtils.createCheckbox( sprcComposite, Messages .getString( "BrowserParameterPage.PagedSearch" ), 1 ); //$NON-NLS-1$ pagedSearchButton.setToolTipText( Messages.getString( "BrowserParameterPage.PagedSearchTooltip" ) ); //$NON-NLS-1$ pagedSearchSizeLabel = BaseWidgetUtils.createLabel( sprcComposite, Messages .getString( "BrowserParameterPage.PageSize" ), 1 ); //$NON-NLS-1$ pagedSearchSizeText = BaseWidgetUtils.createText( sprcComposite, "100", 5, 1 ); //$NON-NLS-1$ pagedSearchScrollModeButton = BaseWidgetUtils.createCheckbox( sprcComposite, Messages .getString( "BrowserParameterPage.ScrollMode" ), 1 ); //$NON-NLS-1$ pagedSearchScrollModeButton.setToolTipText( Messages.getString( "BrowserParameterPage.ScrollModeTooltip" ) ); //$NON-NLS-1$ pagedSearchScrollModeButton.setSelection( true ); } /** * Adds the features input. * * @param parent the parent */ private void addFeaturesInput( Composite parent ) { Composite composite = BaseWidgetUtils.createColumnContainer( parent, 1, 1 ); Group group = BaseWidgetUtils.createGroup( composite, Messages.getString( "BrowserParameterPage.Features" ), 1 ); //$NON-NLS-1$ Composite groupComposite = BaseWidgetUtils.createColumnContainer( group, 1, 1 ); // fetch operational attributes feature fetchOperationalAttributesButton = BaseWidgetUtils.createCheckbox( groupComposite, Messages .getString( "BrowserParameterPage.FetchOperationalAttributesWhileBrowsing" ), 1 ); //$NON-NLS-1$ fetchOperationalAttributesButton.setToolTipText( Messages .getString( "BrowserParameterPage.FetchOperationalAttributesWhileBrowsingTooltip" ) ); //$NON-NLS-1$ fetchOperationalAttributesButton.setSelection( false ); } /** * Adds the limit input. * * @param parent the parent */ public void addLimitInput( Composite parent ) { Composite composite = BaseWidgetUtils.createColumnContainer( parent, 3, 1 ); limitWidget = new LimitWidget( 1000, 0 ); limitWidget.createWidget( composite ); aliasesDereferencingWidget = new AliasesDereferencingWidget( Connection.AliasDereferencingMethod.ALWAYS ); aliasesDereferencingWidget.createWidget( composite ); referralsHandlingWidget = new ReferralsHandlingWidget( Connection.ReferralHandlingMethod.FOLLOW_MANUALLY ); referralsHandlingWidget.createWidget( composite, true ); } /** * @see org.apache.directory.studio.connection.ui.AbstractConnectionParameterPage#validate() */ protected void validate() { // set enabled/disabled state of fields and buttons baseDNCombo.setEnabled( !isAutoFetchBaseDns() ); pagedSearchSizeLabel.setEnabled( isPagedSearch() ); pagedSearchSizeText.setEnabled( isPagedSearch() ); pagedSearchScrollModeButton.setEnabled( isPagedSearch() ); // validate input fields message = null; infoMessage = null; errorMessage = null; if ( !isAutoFetchBaseDns() ) { if ( !Dn.isValid( getBaseDN() ) ) { message = Messages.getString( "BrowserParameterPage.EnterValidBaseDN" ); //$NON-NLS-1$ } } } /** * @see org.apache.directory.studio.connection.ui.AbstractConnectionParameterPage#loadParameters(org.apache.directory.studio.connection.core.ConnectionParameter) */ protected void loadParameters( ConnectionParameter parameter ) { this.connectionParameter = parameter; boolean fetchBaseDns = parameter .getExtendedBoolProperty( IBrowserConnection.CONNECTION_PARAMETER_FETCH_BASE_DNS ); autoFetchBaseDnsButton.setSelection( fetchBaseDns ); String baseDn = parameter.getExtendedProperty( IBrowserConnection.CONNECTION_PARAMETER_BASE_DN ); baseDNCombo.setText( baseDn != null ? baseDn : "" ); //$NON-NLS-1$ int countLimit = parameter.getExtendedIntProperty( IBrowserConnection.CONNECTION_PARAMETER_COUNT_LIMIT ); limitWidget.setCountLimit( countLimit ); int timeLimit = parameter.getExtendedIntProperty( IBrowserConnection.CONNECTION_PARAMETER_TIME_LIMIT ); limitWidget.setTimeLimit( timeLimit ); int referralsHandlingMethodOrdinal = parameter .getExtendedIntProperty( IBrowserConnection.CONNECTION_PARAMETER_REFERRALS_HANDLING_METHOD ); Connection.ReferralHandlingMethod referralsHandlingMethod = Connection.ReferralHandlingMethod .getByOrdinal( referralsHandlingMethodOrdinal ); referralsHandlingWidget.setReferralsHandlingMethod( referralsHandlingMethod ); int aliasesDereferencingMethodOrdinal = parameter .getExtendedIntProperty( IBrowserConnection.CONNECTION_PARAMETER_ALIASES_DEREFERENCING_METHOD ); Connection.AliasDereferencingMethod aliasesDereferencingMethod = Connection.AliasDereferencingMethod .getByOrdinal( aliasesDereferencingMethodOrdinal ); aliasesDereferencingWidget.setAliasesDereferencingMethod( aliasesDereferencingMethod ); boolean manageDsaIT = parameter.getExtendedBoolProperty( IBrowserConnection.CONNECTION_PARAMETER_MANAGE_DSA_IT ); manageDsaItButton.setSelection( manageDsaIT ); boolean fetchSubentries = parameter .getExtendedBoolProperty( IBrowserConnection.CONNECTION_PARAMETER_FETCH_SUBENTRIES ); fetchSubentriesButton.setSelection( fetchSubentries ); boolean pagedSearch = parameter.getExtendedBoolProperty( IBrowserConnection.CONNECTION_PARAMETER_PAGED_SEARCH ); pagedSearchButton.setSelection( pagedSearch ); String pagedSearchSize = parameter .getExtendedProperty( IBrowserConnection.CONNECTION_PARAMETER_PAGED_SEARCH_SIZE ); pagedSearchSizeText.setText( pagedSearchSize != null ? pagedSearchSize : "100" ); //$NON-NLS-1$ boolean pagedSearchScrollMode = parameter .getExtendedBoolProperty( IBrowserConnection.CONNECTION_PARAMETER_PAGED_SEARCH_SCROLL_MODE ); pagedSearchScrollModeButton.setSelection( pagedSearch ? pagedSearchScrollMode : true ); boolean fetchOperationalAttributes = parameter .getExtendedBoolProperty( IBrowserConnection.CONNECTION_PARAMETER_FETCH_OPERATIONAL_ATTRIBUTES ); fetchOperationalAttributesButton.setSelection( fetchOperationalAttributes ); } /** * @see org.apache.directory.studio.connection.ui.AbstractConnectionParameterPage#initListeners() */ protected void initListeners() { autoFetchBaseDnsButton.addSelectionListener( new SelectionAdapter() { public void widgetSelected( SelectionEvent arg0 ) { connectionPageModified(); } } ); fetchBaseDnsButton.addSelectionListener( new SelectionAdapter() { public void widgetSelected( SelectionEvent e ) { Connection connection = getTestConnection(); IBrowserConnection browserConnection = new BrowserConnection( connection ); FetchBaseDNsRunnable runnable = new FetchBaseDNsRunnable( browserConnection ); IStatus status = RunnableContextRunner.execute( runnable, runnableContext, true ); if ( status.isOK() ) { if ( !runnable.getBaseDNs().isEmpty() ) { List<String> baseDNs = runnable.getBaseDNs(); baseDNCombo.setItems( baseDNs.toArray( new String[baseDNs.size()] ) ); baseDNCombo.select( 0 ); String msg = Messages.getString( "BrowserParameterPage.BaseDNResult" ); //$NON-NLS-1$ for ( String baseDN : baseDNs ) { msg += "\n - " + baseDN; //$NON-NLS-1$ } MessageDialog.openInformation( Display.getDefault().getActiveShell(), Messages .getString( "BrowserParameterPage.FetchBaseDNs" ), msg ); //$NON-NLS-1$ } else { MessageDialog.openWarning( Display.getDefault().getActiveShell(), Messages .getString( "BrowserParameterPage.FetchBaseDNs" ), //$NON-NLS-1$ Messages.getString( "BrowserParameterPage.NoBaseDNReturnedFromServer" ) ); //$NON-NLS-1$ autoFetchBaseDnsButton.setSelection( false ); } } } } ); baseDNCombo.addModifyListener( new ModifyListener() { public void modifyText( ModifyEvent event ) { connectionPageModified(); } } ); manageDsaItButton.addSelectionListener( new SelectionAdapter() { public void widgetSelected( SelectionEvent arg0 ) { connectionPageModified(); } } ); fetchSubentriesButton.addSelectionListener( new SelectionAdapter() { public void widgetSelected( SelectionEvent arg0 ) { connectionPageModified(); } } ); pagedSearchButton.addSelectionListener( new SelectionAdapter() { public void widgetSelected( SelectionEvent e ) { connectionPageModified(); } } ); pagedSearchSizeText.addVerifyListener( new VerifyListener() { public void verifyText( VerifyEvent e ) { if ( !e.text.matches( "[0-9]*" ) ) //$NON-NLS-1$ { e.doit = false; } } } ); pagedSearchSizeText.addModifyListener( new ModifyListener() { public void modifyText( ModifyEvent e ) { connectionPageModified(); } } ); fetchOperationalAttributesButton.addSelectionListener( new SelectionAdapter() { public void widgetSelected( SelectionEvent arg0 ) { connectionPageModified(); } } ); } /** * @see org.apache.directory.studio.connection.ui.ConnectionParameterPage#saveParameters(org.apache.directory.studio.connection.core.ConnectionParameter) */ public void saveParameters( ConnectionParameter parameter ) { parameter .setExtendedBoolProperty( IBrowserConnection.CONNECTION_PARAMETER_FETCH_BASE_DNS, isAutoFetchBaseDns() ); parameter.setExtendedProperty( IBrowserConnection.CONNECTION_PARAMETER_BASE_DN, getBaseDN() ); parameter.setExtendedIntProperty( IBrowserConnection.CONNECTION_PARAMETER_COUNT_LIMIT, getCountLimit() ); parameter.setExtendedIntProperty( IBrowserConnection.CONNECTION_PARAMETER_TIME_LIMIT, getTimeLimit() ); parameter.setExtendedIntProperty( IBrowserConnection.CONNECTION_PARAMETER_REFERRALS_HANDLING_METHOD, getReferralsHandlingMethod().getOrdinal() ); parameter.setExtendedIntProperty( IBrowserConnection.CONNECTION_PARAMETER_ALIASES_DEREFERENCING_METHOD, getAliasesDereferencingMethod().getOrdinal() ); parameter.setExtendedBoolProperty( IBrowserConnection.CONNECTION_PARAMETER_MANAGE_DSA_IT, manageDsaIT() ); parameter.setExtendedBoolProperty( IBrowserConnection.CONNECTION_PARAMETER_FETCH_SUBENTRIES, isFetchSubentries() ); parameter.setExtendedBoolProperty( IBrowserConnection.CONNECTION_PARAMETER_PAGED_SEARCH, isPagedSearch() ); parameter.setExtendedIntProperty( IBrowserConnection.CONNECTION_PARAMETER_PAGED_SEARCH_SIZE, getPagedSearchSize() ); parameter.setExtendedBoolProperty( IBrowserConnection.CONNECTION_PARAMETER_PAGED_SEARCH_SCROLL_MODE, isPagedSearchScrollMode() ); parameter.setExtendedBoolProperty( IBrowserConnection.CONNECTION_PARAMETER_FETCH_OPERATIONAL_ATTRIBUTES, isFetchOperationalAttributes() ); } /** * @see org.apache.directory.studio.connection.ui.ConnectionParameterPage#saveDialogSettings() */ public void saveDialogSettings() { } /** * @see org.apache.directory.studio.connection.ui.ConnectionParameterPage#setFocus() */ public void setFocus() { baseDNCombo.setFocus(); } /** * @see org.apache.directory.studio.connection.ui.ConnectionParameterPage#areParametersModifed() */ public boolean areParametersModifed() { int countLimit = connectionParameter .getExtendedIntProperty( IBrowserConnection.CONNECTION_PARAMETER_COUNT_LIMIT ); int timeLimit = connectionParameter.getExtendedIntProperty( IBrowserConnection.CONNECTION_PARAMETER_TIME_LIMIT ); boolean manageDsaIT = connectionParameter .getExtendedBoolProperty( IBrowserConnection.CONNECTION_PARAMETER_MANAGE_DSA_IT ); boolean fetchSubentries = connectionParameter .getExtendedBoolProperty( IBrowserConnection.CONNECTION_PARAMETER_FETCH_SUBENTRIES ); boolean pagedSearch = connectionParameter .getExtendedBoolProperty( IBrowserConnection.CONNECTION_PARAMETER_PAGED_SEARCH ); int pagedSearchSize = connectionParameter .getExtendedIntProperty( IBrowserConnection.CONNECTION_PARAMETER_PAGED_SEARCH_SIZE ); boolean pagedSearchScrollMode = connectionParameter .getExtendedBoolProperty( IBrowserConnection.CONNECTION_PARAMETER_PAGED_SEARCH_SCROLL_MODE ); return isReconnectionRequired() || countLimit != getCountLimit() || timeLimit != getTimeLimit() || manageDsaIT != manageDsaIT() || fetchSubentries != isFetchSubentries() || pagedSearch != isPagedSearch() || pagedSearchSize != getPagedSearchSize() || pagedSearchScrollMode != isPagedSearchScrollMode(); } /** * @see org.apache.directory.studio.connection.ui.ConnectionParameterPage#isReconnectionRequired() */ public boolean isReconnectionRequired() { if ( connectionParameter == null ) { return true; } boolean fetchBaseDns = connectionParameter .getExtendedBoolProperty( IBrowserConnection.CONNECTION_PARAMETER_FETCH_BASE_DNS ); String baseDn = connectionParameter.getExtendedProperty( IBrowserConnection.CONNECTION_PARAMETER_BASE_DN ); int referralsHandlingMethodOrdinal = connectionParameter .getExtendedIntProperty( IBrowserConnection.CONNECTION_PARAMETER_REFERRALS_HANDLING_METHOD ); Connection.ReferralHandlingMethod referralsHandlingMethod = Connection.ReferralHandlingMethod .getByOrdinal( referralsHandlingMethodOrdinal ); int aliasesDereferencingMethodOrdinal = connectionParameter .getExtendedIntProperty( IBrowserConnection.CONNECTION_PARAMETER_ALIASES_DEREFERENCING_METHOD ); Connection.AliasDereferencingMethod aliasesDereferencingMethod = Connection.AliasDereferencingMethod .getByOrdinal( aliasesDereferencingMethodOrdinal ); boolean fetchOperationalAttributes = connectionParameter .getExtendedBoolProperty( IBrowserConnection.CONNECTION_PARAMETER_FETCH_OPERATIONAL_ATTRIBUTES ); return fetchBaseDns != isAutoFetchBaseDns() || !StringUtils.equals( baseDn, getBaseDN() ) || referralsHandlingMethod != getReferralsHandlingMethod() || aliasesDereferencingMethod != getAliasesDereferencingMethod() || fetchOperationalAttributes != isFetchOperationalAttributes(); } /** * {@inheritDoc} */ public void mergeParametersToLdapURL( ConnectionParameter parameter, LdapUrl ldapUrl ) { boolean fetchBaseDns = parameter .getExtendedBoolProperty( IBrowserConnection.CONNECTION_PARAMETER_FETCH_BASE_DNS ); String baseDn = parameter.getExtendedProperty( IBrowserConnection.CONNECTION_PARAMETER_BASE_DN ); if ( !fetchBaseDns && StringUtils.isNotEmpty( baseDn ) ) { ldapUrl.getExtensions().add( new Extension( false, X_BASE_DN, baseDn ) ); } int countLimit = parameter.getExtendedIntProperty( IBrowserConnection.CONNECTION_PARAMETER_COUNT_LIMIT ); if ( countLimit != 0 ) { ldapUrl.getExtensions().add( new Extension( false, X_COUNT_LIMIT, parameter .getExtendedProperty( IBrowserConnection.CONNECTION_PARAMETER_COUNT_LIMIT ) ) ); } int timeLimit = parameter.getExtendedIntProperty( IBrowserConnection.CONNECTION_PARAMETER_TIME_LIMIT ); if ( timeLimit != 0 ) { ldapUrl.getExtensions().add( new Extension( false, X_TIME_LIMIT, parameter .getExtendedProperty( IBrowserConnection.CONNECTION_PARAMETER_TIME_LIMIT ) ) ); } int aliasesDereferencingMethodOrdinal = parameter .getExtendedIntProperty( IBrowserConnection.CONNECTION_PARAMETER_ALIASES_DEREFERENCING_METHOD ); Connection.AliasDereferencingMethod aliasesDereferencingMethod = Connection.AliasDereferencingMethod .getByOrdinal( aliasesDereferencingMethodOrdinal ); switch ( aliasesDereferencingMethod ) { case ALWAYS: // default break; case FINDING: ldapUrl.getExtensions().add( new Extension( false, X_ALIAS_HANDLING, X_ALIAS_HANDLING_FINDING ) ); break; case SEARCH: ldapUrl.getExtensions().add( new Extension( false, X_ALIAS_HANDLING, X_ALIAS_HANDLING_SEARCHING ) ); break; case NEVER: ldapUrl.getExtensions().add( new Extension( false, X_ALIAS_HANDLING, X_ALIAS_HANDLING_NEVER ) ); break; } int referralsHandlingMethodOrdinal = parameter .getExtendedIntProperty( IBrowserConnection.CONNECTION_PARAMETER_REFERRALS_HANDLING_METHOD ); Connection.ReferralHandlingMethod referralsHandlingMethod = Connection.ReferralHandlingMethod .getByOrdinal( referralsHandlingMethodOrdinal ); switch ( referralsHandlingMethod ) { case FOLLOW_MANUALLY: // default break; case IGNORE: ldapUrl.getExtensions().add( new Extension( false, X_REFERRAL_HANDLING, X_REFERRAL_HANDLING_IGNORE ) ); break; case FOLLOW: ldapUrl.getExtensions().add( new Extension( false, X_REFERRAL_HANDLING, X_REFERRAL_HANDLING_FOLLOW ) ); break; } // ManageDsaIT control boolean manageDsaIt = parameter.getExtendedBoolProperty( IBrowserConnection.CONNECTION_PARAMETER_MANAGE_DSA_IT ); if ( manageDsaIt ) { ldapUrl.getExtensions().add( new Extension( false, X_MANAGE_DSA_IT, null ) ); } // fetch subentries boolean fetchSubentries = parameter .getExtendedBoolProperty( IBrowserConnection.CONNECTION_PARAMETER_FETCH_SUBENTRIES ); if ( fetchSubentries ) { ldapUrl.getExtensions().add( new Extension( false, X_FETCH_SUBENTRIES, null ) ); } // paged search boolean pagedSearch = parameter.getExtendedBoolProperty( IBrowserConnection.CONNECTION_PARAMETER_PAGED_SEARCH ); if ( pagedSearch ) { ldapUrl.getExtensions().add( new Extension( false, X_PAGED_SEARCH, null ) ); ldapUrl.getExtensions().add( new Extension( false, X_PAGED_SEARCH_SIZE, parameter .getExtendedProperty( IBrowserConnection.CONNECTION_PARAMETER_PAGED_SEARCH_SIZE ) ) ); boolean pagedSearchScrollMode = parameter .getExtendedBoolProperty( IBrowserConnection.CONNECTION_PARAMETER_PAGED_SEARCH_SCROLL_MODE ); if ( pagedSearchScrollMode ) {
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
true
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/connection/EditorParameterPage.java
plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/connection/EditorParameterPage.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.ldapbrowser.common.widgets.connection; import org.apache.directory.api.ldap.model.url.LdapUrl; import org.apache.directory.api.ldap.model.url.LdapUrl.Extension; import org.apache.directory.studio.common.ui.widgets.BaseWidgetUtils; import org.apache.directory.studio.connection.core.ConnectionParameter; import org.apache.directory.studio.connection.ui.AbstractConnectionParameterPage; import org.apache.directory.studio.ldapbrowser.core.model.IBrowserConnection; import org.apache.directory.studio.ldapbrowser.core.model.IBrowserConnection.ModifyMode; import org.apache.directory.studio.ldapbrowser.core.model.IBrowserConnection.ModifyOrder; import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.widgets.Combo; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Group; import org.eclipse.swt.widgets.Label; /** * The EditorParameterPage is used the edit the editor specific parameters of a * connection. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class EditorParameterPage extends AbstractConnectionParameterPage { private static final String X_MODIFY_MODE = "X-MODIFY-MODE"; //$NON-NLS-1$ private static final String X_MODIFY_MODE_NO_EMR = "X-MODIFY-MODE-NO-EMR"; //$NON-NLS-1$ private static final String X_MODIFY_ORDER = "X-MODIFY-ORDER"; //$NON-NLS-1$ /** The combo for selecting the modify mode */ private Combo modifyModeCombo; /** The combo for selecting the modify mode of attribute with no equality matching rule */ private Combo modifyModeNoEMRCombo; /** The combo for selecting the modify order */ private Combo modifyOrderCombo; /** * Creates a new instance of EditorParameterPage. */ public EditorParameterPage() { } /** * Gets the modify mode. * * @return the modify mode */ private ModifyMode getModifyMode() { return ModifyMode.getByOrdinal( modifyModeCombo.getSelectionIndex() ); } /** * Gets the modify mode of attribute with no equality matching rule. * * @return the modify mode of attribute with no equality matching rule */ private ModifyMode getModifyModeNoEMR() { return ModifyMode.getByOrdinal( modifyModeNoEMRCombo.getSelectionIndex() ); } /** * Gets the modify mode. * * @return the modify mode */ private ModifyOrder getModifyOrder() { return ModifyOrder.getByOrdinal( modifyOrderCombo.getSelectionIndex() ); } /** * @see org.apache.directory.studio.connection.ui.AbstractConnectionParameterPage#createComposite(org.eclipse.swt.widgets.Composite) */ protected void createComposite( Composite parent ) { addModifyInput( parent ); } /** * Adds the modify input. * * @param parent the parent */ private void addModifyInput( Composite parent ) { Composite composite = BaseWidgetUtils.createColumnContainer( parent, 1, 1 ); Group group = BaseWidgetUtils.createGroup( composite, Messages.getString( "EditorParameterPage.ModifyGroup" ), 1 ); //$NON-NLS-1$ Composite groupComposite = BaseWidgetUtils.createColumnContainer( group, 2, 1 ); Label modifyModeLabel = BaseWidgetUtils.createLabel( groupComposite, Messages .getString( "EditorParameterPage.ModifyMode" ), 1 ); //$NON-NLS-1$ modifyModeLabel.setToolTipText( Messages.getString( "EditorParameterPage.ModifyModeTooltip" ) ); //$NON-NLS-1$ String[] modifyModeItems = new String[] { Messages.getString( "EditorParameterPage.ModifyModeDefault" ), //$NON-NLS-1$ Messages.getString( "EditorParameterPage.ModifyModeReplace" ), //$NON-NLS-1$ Messages.getString( "EditorParameterPage.ModifyModeAddDel" ) }; //$NON-NLS-1$ modifyModeCombo = BaseWidgetUtils.createReadonlyCombo( groupComposite, modifyModeItems, 0, 1 ); modifyModeCombo.setToolTipText( Messages.getString( "EditorParameterPage.ModifyModeTooltip" ) ); //$NON-NLS-1$ Label modifyModeNoEMRLabel = BaseWidgetUtils.createLabel( groupComposite, Messages .getString( "EditorParameterPage.ModifyModeNoEMR" ), 1 ); //$NON-NLS-1$ modifyModeNoEMRLabel.setToolTipText( Messages.getString( "EditorParameterPage.ModifyModeNoEMRTooltip" ) ); //$NON-NLS-1$ String[] modifyModeNoEMRItems = new String[] { Messages.getString( "EditorParameterPage.ModifyModeDefault" ), //$NON-NLS-1$ Messages.getString( "EditorParameterPage.ModifyModeReplace" ), //$NON-NLS-1$ Messages.getString( "EditorParameterPage.ModifyModeAddDel" ) }; //$NON-NLS-1$ modifyModeNoEMRCombo = BaseWidgetUtils.createReadonlyCombo( groupComposite, modifyModeNoEMRItems, 0, 1 ); modifyModeNoEMRCombo.setToolTipText( Messages.getString( "EditorParameterPage.ModifyModeNoEMRTooltip" ) ); //$NON-NLS-1$ Label modifyOrderLabel = BaseWidgetUtils.createLabel( groupComposite, Messages .getString( "EditorParameterPage.ModifyOrder" ), 1 ); //$NON-NLS-1$ modifyOrderLabel.setToolTipText( Messages.getString( "EditorParameterPage.ModifyOrderTooltip" ) ); //$NON-NLS-1$ String[] modifyOrderItems = new String[] { Messages.getString( "EditorParameterPage.ModifyOrderDelFirst" ), //$NON-NLS-1$ Messages.getString( "EditorParameterPage.ModifyOrderAddFirst" ) }; //$NON-NLS-1$ modifyOrderCombo = BaseWidgetUtils.createReadonlyCombo( groupComposite, modifyOrderItems, 0, 1 ); modifyOrderCombo.setToolTipText( Messages.getString( "EditorParameterPage.ModifyOrderTooltip" ) ); //$NON-NLS-1$ } /** * @see org.apache.directory.studio.connection.ui.AbstractConnectionParameterPage#validate() */ protected void validate() { } /** * @see org.apache.directory.studio.connection.ui.AbstractConnectionParameterPage#loadParameters(org.apache.directory.studio.connection.core.ConnectionParameter) */ protected void loadParameters( ConnectionParameter parameter ) { this.connectionParameter = parameter; int modifyMode = parameter.getExtendedIntProperty( IBrowserConnection.CONNECTION_PARAMETER_MODIFY_MODE ); modifyModeCombo.select( modifyMode ); int modifyModeNoEMR = parameter .getExtendedIntProperty( IBrowserConnection.CONNECTION_PARAMETER_MODIFY_MODE_NO_EMR ); modifyModeNoEMRCombo.select( modifyModeNoEMR ); int modifyOrder = parameter.getExtendedIntProperty( IBrowserConnection.CONNECTION_PARAMETER_MODIFY_ORDER ); modifyOrderCombo.select( modifyOrder ); } /** * @see org.apache.directory.studio.connection.ui.AbstractConnectionParameterPage#initListeners() */ protected void initListeners() { modifyModeCombo.addSelectionListener( new SelectionAdapter() { public void widgetSelected( SelectionEvent event ) { connectionPageModified(); } } ); modifyModeNoEMRCombo.addSelectionListener( new SelectionAdapter() { public void widgetSelected( SelectionEvent event ) { connectionPageModified(); } } ); modifyOrderCombo.addSelectionListener( new SelectionAdapter() { public void widgetSelected( SelectionEvent event ) { connectionPageModified(); } } ); } /** * @see org.apache.directory.studio.connection.ui.ConnectionParameterPage#saveParameters(org.apache.directory.studio.connection.core.ConnectionParameter) */ public void saveParameters( ConnectionParameter parameter ) { parameter.setExtendedIntProperty( IBrowserConnection.CONNECTION_PARAMETER_MODIFY_MODE, getModifyMode() .getOrdinal() ); parameter.setExtendedIntProperty( IBrowserConnection.CONNECTION_PARAMETER_MODIFY_MODE_NO_EMR, getModifyModeNoEMR().getOrdinal() ); parameter.setExtendedIntProperty( IBrowserConnection.CONNECTION_PARAMETER_MODIFY_ORDER, getModifyOrder() .getOrdinal() ); } /** * @see org.apache.directory.studio.connection.ui.ConnectionParameterPage#saveDialogSettings() */ public void saveDialogSettings() { } /** * @see org.apache.directory.studio.connection.ui.ConnectionParameterPage#setFocus() */ public void setFocus() { } /** * @see org.apache.directory.studio.connection.ui.ConnectionParameterPage#areParametersModifed() */ public boolean areParametersModifed() { int modifyMode = connectionParameter .getExtendedIntProperty( IBrowserConnection.CONNECTION_PARAMETER_MODIFY_MODE ); int modifyModeNoEMR = connectionParameter .getExtendedIntProperty( IBrowserConnection.CONNECTION_PARAMETER_MODIFY_MODE_NO_EMR ); int modifyOrder = connectionParameter .getExtendedIntProperty( IBrowserConnection.CONNECTION_PARAMETER_MODIFY_ORDER ); return modifyMode != getModifyMode().getOrdinal() || modifyModeNoEMR != getModifyModeNoEMR().getOrdinal() || modifyOrder != getModifyOrder().getOrdinal(); } /** * @see org.apache.directory.studio.connection.ui.ConnectionParameterPage#isReconnectionRequired() */ public boolean isReconnectionRequired() { if ( connectionParameter == null ) { return true; } return false; } /** * {@inheritDoc} */ public void mergeParametersToLdapURL( ConnectionParameter parameter, LdapUrl ldapUrl ) { int modifyMode = parameter.getExtendedIntProperty( IBrowserConnection.CONNECTION_PARAMETER_MODIFY_MODE ); if ( modifyMode != 0 ) { ldapUrl.getExtensions().add( new Extension( false, X_MODIFY_MODE, parameter .getExtendedProperty( IBrowserConnection.CONNECTION_PARAMETER_MODIFY_MODE ) ) ); } int modifyModeNoEMR = parameter .getExtendedIntProperty( IBrowserConnection.CONNECTION_PARAMETER_MODIFY_MODE_NO_EMR ); if ( modifyModeNoEMR != 0 ) { ldapUrl.getExtensions().add( new Extension( false, X_MODIFY_MODE_NO_EMR, parameter .getExtendedProperty( IBrowserConnection.CONNECTION_PARAMETER_MODIFY_MODE_NO_EMR ) ) ); } int modifyOrder = parameter.getExtendedIntProperty( IBrowserConnection.CONNECTION_PARAMETER_MODIFY_ORDER ); if ( modifyOrder != 0 ) { ldapUrl.getExtensions().add( new Extension( false, X_MODIFY_ORDER, parameter .getExtendedProperty( IBrowserConnection.CONNECTION_PARAMETER_MODIFY_ORDER ) ) ); } } /** * {@inheritDoc} */ public void mergeLdapUrlToParameters( LdapUrl ldapUrl, ConnectionParameter parameter ) { // modify mode, DEFAULT if non-numeric or absent String modifyMode = ldapUrl.getExtensionValue( X_MODIFY_MODE ); try { parameter.setExtendedIntProperty( IBrowserConnection.CONNECTION_PARAMETER_MODIFY_MODE, Integer.valueOf( modifyMode ) ); } catch ( NumberFormatException e ) { parameter.setExtendedIntProperty( IBrowserConnection.CONNECTION_PARAMETER_MODIFY_MODE, ModifyMode.DEFAULT .getOrdinal() ); } // modify mode no EMR, DEFAULT if non-numeric or absent String modifyModeNoEMR = ldapUrl.getExtensionValue( X_MODIFY_MODE_NO_EMR ); try { parameter.setExtendedIntProperty( IBrowserConnection.CONNECTION_PARAMETER_MODIFY_MODE_NO_EMR, Integer.valueOf( modifyModeNoEMR ) ); } catch ( NumberFormatException e ) { parameter.setExtendedIntProperty( IBrowserConnection.CONNECTION_PARAMETER_MODIFY_MODE_NO_EMR, ModifyMode.DEFAULT.getOrdinal() ); } // modify order, DEL_FIRST if non-numeric or absent String modifyOrder = ldapUrl.getExtensionValue( X_MODIFY_ORDER ); try { parameter.setExtendedIntProperty( IBrowserConnection.CONNECTION_PARAMETER_MODIFY_ORDER, Integer.valueOf( modifyOrder ) ); } catch ( NumberFormatException e ) { parameter.setExtendedIntProperty( IBrowserConnection.CONNECTION_PARAMETER_MODIFY_ORDER, ModifyOrder.DELETE_FIRST.getOrdinal() ); } } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/connection/Messages.java
plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/connection/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.ldapbrowser.common.widgets.connection; 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/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/search/EntryWidget.java
plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/search/EntryWidget.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.ldapbrowser.common.widgets.search; import org.apache.directory.api.ldap.model.exception.LdapInvalidDnException; import org.apache.directory.api.ldap.model.name.Dn; import org.apache.directory.studio.common.ui.HistoryUtils; import org.apache.directory.studio.common.ui.widgets.AbstractWidget; import org.apache.directory.studio.common.ui.widgets.BaseWidgetUtils; import org.apache.directory.studio.connection.core.DnUtils; import org.apache.directory.studio.connection.ui.RunnableContextRunner; import org.apache.directory.studio.ldapbrowser.common.BrowserCommonActivator; import org.apache.directory.studio.ldapbrowser.common.BrowserCommonConstants; import org.apache.directory.studio.ldapbrowser.common.dialogs.SelectEntryDialog; import org.apache.directory.studio.ldapbrowser.core.jobs.ReadEntryRunnable; import org.apache.directory.studio.ldapbrowser.core.model.IBrowserConnection; import org.apache.directory.studio.ldapbrowser.core.model.IEntry; 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.widgets.Button; import org.eclipse.swt.widgets.Combo; import org.eclipse.swt.widgets.Composite; /** * The EntryWidget could be used to select an entry. * It is composed of : * <ul> * <li>a combo to manually enter an Dn or to choose one from the history * <li>an up button to switch to the parent's Dn * <li>a browse button to open a {@link SelectEntryDialog} * </ul> * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class EntryWidget extends AbstractWidget { /** The Dn combo. */ private Combo dnCombo; /** The up button. */ private Button upButton; /** The entry browse button. */ private Button entryBrowseButton; /** The connection. */ private IBrowserConnection browserConnection; /** The selected Dn. */ private Dn dn; /** The suffix. */ private Dn suffix; /** Flag indicating if using local name for the dn */ boolean useLocalName; /** * Creates a new instance of EntryWidget. */ public EntryWidget() { browserConnection = null; dn = null; } /** * Creates a new instance of EntryWidget. * * @param browserConnection the connection * @param dn the initial Dn */ public EntryWidget( IBrowserConnection browserConnection, Dn dn ) { this( browserConnection, dn, null, false ); } /** * Creates a new instance of EntryWidget. * * @param browserConnection the connection * @param dn the initial Dn * @param suffix the suffix * @param useLocalName true to use local name for the Dn */ public EntryWidget( IBrowserConnection browserConnection, Dn dn, Dn suffix, boolean useLocalName ) { this.browserConnection = browserConnection; this.dn = dn; this.suffix = suffix; this.useLocalName = useLocalName; } /** * Creates the widget. * * @param parent the parent */ public void createWidget( final Composite parent ) { // Dn combo Composite textAndUpComposite = BaseWidgetUtils.createColumnContainer( parent, 2, 1 ); dnCombo = BaseWidgetUtils.createCombo( textAndUpComposite, new String[0], -1, 1 ); GridData gd = new GridData( GridData.FILL_HORIZONTAL ); gd.horizontalSpan = 1; gd.widthHint = 30; dnCombo.setLayoutData( gd ); // Dn history String[] history = HistoryUtils.load( BrowserCommonActivator.getDefault().getDialogSettings(), BrowserCommonConstants.DIALOGSETTING_KEY_DN_HISTORY ); dnCombo.setItems( history ); dnCombo.addModifyListener( new ModifyListener() { public void modifyText( ModifyEvent e ) { try { dn = new Dn( dnCombo.getText() ); } catch ( LdapInvalidDnException e1 ) { dn = null; } internalSetEnabled(); notifyListeners(); } } ); // Up button upButton = new Button( textAndUpComposite, SWT.PUSH ); upButton.setToolTipText( Messages.getString( "EntryWidget.Parent" ) ); //$NON-NLS-1$ upButton.setImage( BrowserCommonActivator.getDefault().getImage( BrowserCommonConstants.IMG_PARENT ) ); upButton.setEnabled( false ); upButton.addSelectionListener( new SelectionAdapter() { public void widgetSelected( SelectionEvent e ) { if ( !Dn.isNullOrEmpty( dn ) ) { dn = dn.getParent(); dnChanged(); internalSetEnabled(); notifyListeners(); } } } ); // Browse button entryBrowseButton = BaseWidgetUtils.createButton( parent, Messages.getString( "EntryWidget.BrowseButton" ), 1 ); //$NON-NLS-1$ entryBrowseButton.addSelectionListener( new SelectionAdapter() { public void widgetSelected( SelectionEvent e ) { if ( browserConnection != null ) { // get root entry IEntry rootEntry = browserConnection.getRootDSE(); if ( suffix != null && suffix.size() > 0 ) { rootEntry = browserConnection.getEntryFromCache( suffix ); if ( rootEntry == null ) { ReadEntryRunnable runnable = new ReadEntryRunnable( browserConnection, suffix ); RunnableContextRunner.execute( runnable, null, true ); rootEntry = runnable.getReadEntry(); } } // calculate initial Dn Dn initialDn = dn; if ( useLocalName && suffix != null && suffix.size() > 0 ) { if ( initialDn != null && initialDn.size() > 0 ) { try { initialDn = initialDn.add( suffix ); } catch ( LdapInvalidDnException lide ) { // Do nothing } } } // get initial entry IEntry entry = rootEntry; if ( initialDn != null && initialDn.size() > 0 ) { entry = browserConnection.getEntryFromCache( initialDn ); if ( entry == null ) { ReadEntryRunnable runnable = new ReadEntryRunnable( browserConnection, initialDn ); RunnableContextRunner.execute( runnable, null, true ); entry = runnable.getReadEntry(); } } // open dialog SelectEntryDialog dialog = new SelectEntryDialog( parent.getShell(), Messages .getString( "EntryWidget.SelectDN" ), rootEntry, entry ); //$NON-NLS-1$ dialog.open(); IEntry selectedEntry = dialog.getSelectedEntry(); // get selected Dn if ( selectedEntry != null ) { dn = selectedEntry.getDn(); if ( useLocalName && suffix != null && suffix.size() > 0 ) { dn = DnUtils.getPrefixName( dn, suffix ); } dnChanged(); internalSetEnabled(); notifyListeners(); } } } } ); dnChanged(); internalSetEnabled(); } /** * Notifies that the Dn has been changed. */ private void dnChanged() { if ( ( dnCombo != null ) && ( entryBrowseButton != null ) ) { dnCombo.setText( dn != null ? dn.getName() : "" ); //$NON-NLS-1$ } } /** * Sets the enabled state of the widget. * * @param enabled true to enable the widget, false to disable the widget */ public void setEnabled( boolean enabled ) { dnCombo.setEnabled( enabled ); if ( enabled ) { this.dnChanged(); } internalSetEnabled(); } /** * Internal set enabled. */ private void internalSetEnabled() { upButton.setEnabled( !Dn.isNullOrEmpty( dn ) && dnCombo.isEnabled() ); entryBrowseButton.setEnabled( browserConnection != null && dnCombo.isEnabled() ); } /** * Saves dialog settings. */ public void saveDialogSettings() { HistoryUtils.save( BrowserCommonActivator.getDefault().getDialogSettings(), BrowserCommonConstants.DIALOGSETTING_KEY_DN_HISTORY, this.dnCombo.getText() ); } /** * Gets the suffix Dn or <code>null</code> if not set. * * @return the suffix Dn or <code>null</code> if not set */ public Dn getSuffix() { return suffix; } /** * Gets the Dn or <code>null</code> if the Dn isn't valid. * * @return the Dn or <code>null</code> if the Dn isn't valid */ public Dn getDn() { return dn; } /** * Gets the browser connection. * * @return the browser connection */ public IBrowserConnection getBrowserConnection() { return browserConnection; } /** * Sets the input. * * @param dn the Dn * @param browserConnection the connection */ public void setInput( IBrowserConnection browserConnection, Dn dn ) { setInput( browserConnection, dn, null, false ); } /** * Sets the input. * * @param browserConnection the connection * @param dn the Dn * @param suffix the suffix * @param useLocalName true to use local name for the Dn */ public void setInput( IBrowserConnection browserConnection, Dn dn, Dn suffix, boolean useLocalName ) { if ( ( this.browserConnection != browserConnection ) || ( this.dn != dn ) || ( this.suffix != suffix ) ) { this.browserConnection = browserConnection; this.dn = dn; this.suffix = suffix; this.useLocalName = useLocalName; dnChanged(); } } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/search/FilterWidget.java
plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/search/FilterWidget.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.ldapbrowser.common.widgets.search; import org.apache.directory.api.ldap.model.constants.LdapConstants; import org.apache.directory.studio.common.ui.HistoryUtils; import org.apache.directory.studio.common.ui.widgets.AbstractWidget; 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.BrowserCommonActivator; import org.apache.directory.studio.ldapbrowser.common.BrowserCommonConstants; import org.apache.directory.studio.ldapbrowser.common.dialogs.FilterDialog; import org.apache.directory.studio.ldapbrowser.common.filtereditor.FilterContentAssistProcessor; import org.apache.directory.studio.ldapbrowser.core.model.IBrowserConnection; import org.apache.directory.studio.ldapbrowser.core.model.filter.parser.LdapFilterParser; import org.eclipse.jface.fieldassist.ComboContentAdapter; import org.eclipse.swt.SWT; import org.eclipse.swt.events.ModifyEvent; import org.eclipse.swt.events.ModifyListener; import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.events.VerifyEvent; import org.eclipse.swt.events.VerifyListener; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Combo; import org.eclipse.swt.widgets.Composite; /** * The FileterWidget could be used to specify an LDAP filter. * It is composed of a combo with a content assist to enter * a filter and a button to open a {@link FilterDialog}. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class FilterWidget extends AbstractWidget { /** The filter combo. */ private Combo filterCombo; /** The filter content proposal adapter */ private ExtendedContentAssistCommandAdapter filterCPA; /** The button to open the filter editor. */ private Button filterEditorButton; /** The content assist processor. */ private FilterContentAssistProcessor contentAssistProcessor; /** The connection. */ private IBrowserConnection browserConnection; /** The inital filter. */ private String initalFilter; /** The filter parser. */ private LdapFilterParser parser; /** * Creates a new instance of FilterWidget. * * @param initalFilter the initial filter */ public FilterWidget( String initalFilter ) { this.initalFilter = initalFilter; } /** * Creates a new instance of FilterWidget with no connection and * no initial filter. */ public FilterWidget() { this.browserConnection = null; this.initalFilter = null; } /** * Creates the widget. * * @param parent the parent */ public void createWidget( final Composite parent ) { Composite composite = BaseWidgetUtils.createColumnContainer( parent, 1, 1 ); GridData gd = new GridData( GridData.FILL_HORIZONTAL ); gd.horizontalSpan = 1; gd.widthHint = 30; composite.setLayoutData( gd ); // filter combo with field decoration and content proposal filterCombo = BaseWidgetUtils.createCombo( composite, new String[0], -1, 1 ); filterCombo.addModifyListener( new ModifyListener() { public void modifyText( ModifyEvent e ) { notifyListeners(); } } ); filterCombo.addVerifyListener( new VerifyListener() { public void verifyText( VerifyEvent e ) { // close proposal popup when paste a string // either with 3rd mouse button (linux) if ( !filterCombo.getText().equals( e.text ) && e.character == 0 && e.start == e.end ) { filterCPA.closeProposalPopup(); } // or with ctrl+v / command+v if ( !filterCombo.getText().equals( e.text ) && e.stateMask == SWT.MOD1 && e.start == e.end ) { filterCPA.closeProposalPopup(); } } } ); parser = new LdapFilterParser(); contentAssistProcessor = new FilterContentAssistProcessor( parser ); filterCPA = new ExtendedContentAssistCommandAdapter( filterCombo, new ComboContentAdapter(), contentAssistProcessor, null, null, true ); // auto edit strategy new FilterWidgetAutoEditStrategyAdapter( filterCombo, parser ); // Filter editor button filterEditorButton = BaseWidgetUtils.createButton( parent, Messages .getString( "FilterWidget.FilterEditorButton" ), 1 ); //$NON-NLS-1$ filterEditorButton.addSelectionListener( new SelectionAdapter() { public void widgetSelected( SelectionEvent e ) { if ( browserConnection != null ) { FilterDialog dialog = new FilterDialog( parent.getShell(), Messages .getString( "FilterWidget.FilterEditor" ), filterCombo.getText(), //$NON-NLS-1$ browserConnection ); dialog.open(); String filter = dialog.getFilter(); if ( filter != null ) { filterCombo.setText( filter ); } } } } ); // filter history String[] history = HistoryUtils.load( BrowserCommonActivator.getDefault().getDialogSettings(), BrowserCommonConstants.DIALOGSETTING_KEY_SEARCH_FILTER_HISTORY ); filterCombo.setItems( history ); // initial values filterCombo.setText( initalFilter == null ? LdapConstants.OBJECT_CLASS_STAR : initalFilter ); //$NON-NLS-1$ } /** * Gets the filter or null if the filter is invalid. * * @return the filter or null if the filter is invalid */ public String getFilter() { if ( "".equals( filterCombo.getText() ) ) //$NON-NLS-1$ { return ""; //$NON-NLS-1$ } parser.parse( filterCombo.getText() ); return parser.getModel().isValid() ? filterCombo.getText() : null; } /** * Sets the filter. * * @param filter the filter */ public void setFilter( String filter ) { if ( filterCombo == null ) { initalFilter = filter; } else { filterCombo.setText( filter ); } } /** * Sets the browser connection. * * @param browserConnection the browser connection */ public void setBrowserConnection( IBrowserConnection browserConnection ) { if ( this.browserConnection != browserConnection ) { this.browserConnection = browserConnection; if ( filterCombo != null ) { contentAssistProcessor.setSchema( browserConnection == null ? null : browserConnection.getSchema() ); filterCPA.setAutoActivationCharacters( contentAssistProcessor .getCompletionProposalAutoActivationCharacters() ); } } } /** * Saves dialog settings. */ public void saveDialogSettings() { HistoryUtils.save( BrowserCommonActivator.getDefault().getDialogSettings(), BrowserCommonConstants.DIALOGSETTING_KEY_SEARCH_FILTER_HISTORY, filterCombo.getText() ); } /** * Sets the focus. */ public void setFocus() { // filterCombo.setFocus(); } /** * Sets the enabled state of the widget. * * @param b true to enable the widget, false to disable the widget */ public void setEnabled( boolean b ) { filterCombo.setEnabled( b ); filterEditorButton.setEnabled( b ); } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/search/ReturningAttributesContentAssistProcessor.java
plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/search/ReturningAttributesContentAssistProcessor.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.ldapbrowser.common.widgets.search; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.HashSet; import java.util.Iterator; import java.util.List; import java.util.Set; import org.eclipse.jface.contentassist.IContentAssistSubjectControl; import org.eclipse.jface.contentassist.ISubjectControlContentAssistProcessor; import org.eclipse.jface.text.IDocument; import org.eclipse.jface.text.ITextViewer; import org.eclipse.jface.text.contentassist.CompletionProposal; import org.eclipse.jface.text.contentassist.ICompletionProposal; import org.eclipse.jface.text.contentassist.IContextInformation; import org.eclipse.jface.text.contentassist.IContextInformationValidator; /** * The ReturningAttributesContentAssistProcessor provides proposals for the * {@link ReturningAttributesWidget}. It splits the comma separted text input * into separate regions. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class ReturningAttributesContentAssistProcessor implements ISubjectControlContentAssistProcessor { /** The auto activation characters */ private char[] autoActivationCharacters; /** The possible attribute types */ private List<String> proposals; /** * Creates a new instance of ReturningAttributesContentAssistProcessor. * * @param proposals the proposals */ public ReturningAttributesContentAssistProcessor( List<String> proposals ) { super(); setProposals( proposals ); } /** * {@inheritDoc} */ public char[] getCompletionProposalAutoActivationCharacters() { return autoActivationCharacters; } /** * Sets the possible attribute types. * * @param newProposals the possible strings */ public void setProposals( List<String> newProposals ) { if ( newProposals == null ) { proposals = new ArrayList<String>(); } else { proposals = newProposals; } // sort proposals, attributes first Comparator<? super String> comparator = new Comparator<String>() { public int compare( String o1, String o2 ) { if ( "+".equals( o1 ) && !"+".equals( o2 ) ) //$NON-NLS-1$ //$NON-NLS-2$ { return 4; } if ( "+".equals( o2 ) && !"+".equals( o1 ) ) //$NON-NLS-1$ //$NON-NLS-2$ { return -4; } if ( "*".equals( o1 ) && !"*".equals( o2 ) ) //$NON-NLS-1$ //$NON-NLS-2$ { return 3; } if ( "*".equals( o2 ) && !"*".equals( o1 ) ) //$NON-NLS-1$ //$NON-NLS-2$ { return -3; } if ( o1.startsWith( "@" ) && !o2.startsWith( "@" ) ) //$NON-NLS-1$ //$NON-NLS-2$ { return 2; } if ( o2.startsWith( "@" ) && !o1.startsWith( "@" ) ) //$NON-NLS-1$ //$NON-NLS-2$ { return -2; } return o1.compareToIgnoreCase( o2 ); } }; Collections.sort( proposals, comparator ); // set auto activation characters Set<Character> characterSet = new HashSet<Character>(); for ( String string : proposals ) { for ( int k = 0; k < string.length(); k++ ) { char ch = string.charAt( k ); characterSet.add( Character.toLowerCase( ch ) ); characterSet.add( Character.toUpperCase( ch ) ); } } autoActivationCharacters = new char[characterSet.size()]; int i = 0; for ( Iterator<Character> it = characterSet.iterator(); it.hasNext(); ) { Character ch = it.next(); autoActivationCharacters[i] = ch.charValue(); i++; } } /** * {@inheritDoc} * * This implementation always returns null. */ public ICompletionProposal[] computeCompletionProposals( ITextViewer viewer, int offset ) { return null; } /** * {@inheritDoc} */ public ICompletionProposal[] computeCompletionProposals( IContentAssistSubjectControl contentAssistSubjectControl, int documentOffset ) { IDocument document = contentAssistSubjectControl.getDocument(); String text = document.get(); // search start of current attribute type int start = 0; for ( int i = documentOffset - 1; i >= 0; i-- ) { char c = text.charAt( i ); if ( c == ',' || Character.isWhitespace( c ) ) { start = i + 1; break; } } String attribute = text.substring( start, documentOffset ); // create proposal list List<ICompletionProposal> proposalList = new ArrayList<ICompletionProposal>(); for ( String string : proposals ) { if ( string.toUpperCase().startsWith( attribute.toUpperCase() ) ) { ICompletionProposal proposal = new CompletionProposal( string + ", ", start, //$NON-NLS-1$ documentOffset - start, string.length() + 2, null, string, null, null ); proposalList.add( proposal ); } } return proposalList.toArray( new ICompletionProposal[proposalList.size()] ); } /** * {@inheritDoc} * * This implementation always returns null. */ public char[] getContextInformationAutoActivationCharacters() { return null; } /** * {@inheritDoc} * * This implementation always returns null. */ public IContextInformation[] computeContextInformation( ITextViewer viewer, int offset ) { return null; } /** * {@inheritDoc} * * This implementation always returns null. */ public IContextInformation[] computeContextInformation( IContentAssistSubjectControl contentAssistSubjectControl, int documentOffset ) { return null; } /** * {@inheritDoc} * * This implementation always returns null. */ public String getErrorMessage() { return null; } /** * {@inheritDoc} * * This implementation always returns null. */ public IContextInformationValidator getContextInformationValidator() { 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/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/search/SearchPageWrapper.java
plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/search/SearchPageWrapper.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.ldapbrowser.common.widgets.search; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.HashSet; import java.util.List; import java.util.Set; import org.apache.directory.api.ldap.model.constants.SchemaConstants; import org.apache.directory.api.ldap.model.message.Control; import org.apache.directory.api.ldap.model.message.SearchScope; import org.apache.directory.api.ldap.model.message.controls.ManageDsaIT; import org.apache.directory.api.ldap.model.message.controls.PagedResults; import org.apache.directory.api.ldap.model.message.controls.PagedResultsImpl; import org.apache.directory.api.ldap.model.message.controls.Subentries; import org.apache.directory.api.ldap.model.name.Dn; import org.apache.directory.api.ldap.model.schema.AttributeType; import org.apache.directory.studio.common.ui.widgets.AbstractWidget; 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.connection.core.Connection; import org.apache.directory.studio.connection.core.Controls; import org.apache.directory.studio.ldapbrowser.core.jobs.SearchRunnable; import org.apache.directory.studio.ldapbrowser.core.jobs.StudioBrowserJob; import org.apache.directory.studio.ldapbrowser.core.model.IBrowserConnection; import org.apache.directory.studio.ldapbrowser.core.model.ISearch; import org.apache.directory.studio.ldapbrowser.core.model.schema.SchemaUtils; import org.eclipse.swt.events.ModifyEvent; import org.eclipse.swt.events.ModifyListener; import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.events.VerifyEvent; import org.eclipse.swt.events.VerifyListener; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Group; import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Text; /** * The SearchPageWrapper is used to arrange all input elements of a * search page. It is used by the search page, the search properties page, * the batch operation wizard and the export wizards. * * The style is used to specify the invisible and readonly elements. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class SearchPageWrapper extends AbstractWidget { /** The default style */ public static final int NONE = 0; /** Style for invisible name field */ public static final int NAME_INVISIBLE = 1 << 1; /** Style for read-only name field */ public static final int NAME_READONLY = 1 << 2; /** Style for invisible connection field */ public static final int CONNECTION_INVISIBLE = 1 << 3; /** Style for read-only connection field */ public static final int CONNECTION_READONLY = 1 << 4; /** Style for invisible search base field */ public static final int SEARCHBASE_INVISIBLE = 1 << 5; /** Style for read-only search base field */ public static final int SEARCHBASE_READONLY = 1 << 6; /** Style for invisible filter field */ public static final int FILTER_INVISIBLE = 1 << 7; /** Style for read-only filter field */ public static final int FILTER_READONLY = 1 << 8; /** Style for invisible returning attributes field */ public static final int RETURNINGATTRIBUTES_INVISIBLE = 1 << 9; /** Style for read-only returning attributes field */ public static final int RETURNINGATTRIBUTES_READONLY = 1 << 10; /** Style for visible return Dn checkbox */ public static final int RETURN_DN_VISIBLE = 1 << 11; /** Style for checked return Dn checkbox */ public static final int RETURN_DN_CHECKED = 1 << 12; /** Style for visible return all attributes checkbox */ public static final int RETURN_ALLATTRIBUTES_VISIBLE = 1 << 13; /** Style for checked return all attributes checkbox */ public static final int RETURN_ALLATTRIBUTES_CHECKED = 1 << 14; /** Style for visible return operational attributes checkbox */ public static final int RETURN_OPERATIONALATTRIBUTES_VISIBLE = 1 << 15; /** Style for checked return operational attributes checkbox */ public static final int RETURN_OPERATIONALATTRIBUTES_CHECKED = 1 << 16; /** Style for invisible options */ public static final int OPTIONS_INVISIBLE = 1 << 21; /** Style for read-only scope options */ public static final int SCOPEOPTIONS_READONLY = 1 << 22; /** Style for read-only limit options */ public static final int LIMITOPTIONS_READONLY = 1 << 23; /** Style for read-only alias options */ public static final int ALIASOPTIONS_READONLY = 1 << 24; /** Style for read-only referrals options */ public static final int REFERRALOPTIONS_READONLY = 1 << 25; /** Style for invisible follow referrals manually*/ public static final int REFERRALOPTIONS_FOLLOW_MANUAL_INVISIBLE = 1 << 26; /** Style for invisible controls fields */ public static final int CONTROLS_INVISIBLE = 1 << 30; /** The style. */ protected int style; /** The search name label. */ protected Label searchNameLabel; /** The search name text. */ protected Text searchNameText; /** The connection label. */ protected Label connectionLabel; /** The browser connection widget. */ protected BrowserConnectionWidget browserConnectionWidget; /** The search base label. */ protected Label searchBaseLabel; /** The search base widget. */ protected EntryWidget searchBaseWidget; /** The filter label. */ protected Label filterLabel; /** The filter widget. */ protected FilterWidget filterWidget; /** The returning attributes label. */ protected Label returningAttributesLabel; /** The returning attributes widget. */ protected ReturningAttributesWidget returningAttributesWidget; /** The return dn button. */ protected Button returnDnButton; /** The return all attributes button. */ protected Button returnAllAttributesButton; /** The return operational attributes button. */ protected Button returnOperationalAttributesButton; /** The scope widget. */ protected ScopeWidget scopeWidget; /** The limit widget. */ protected LimitWidget limitWidget; /** The aliases dereferencing widget. */ protected AliasesDereferencingWidget aliasesDereferencingWidget; /** The referrals handling widget. */ protected ReferralsHandlingWidget referralsHandlingWidget; /** The control group. */ protected Group controlGroup; /** The ManageDsaIT control button. */ protected Button manageDsaItControlButton; /** The subentries control button. */ protected Button subentriesControlButton; /** The paged search control button. */ protected Button pagedSearchControlButton; /** The paged search control size label. */ protected Label pagedSearchControlSizeLabel; /** The paged search control size text. */ protected Text pagedSearchControlSizeText; /** The paged search control scroll button. */ protected Button pagedSearchControlScrollButton; /** * Creates a new instance of SearchPageWrapper. * * @param style the style */ public SearchPageWrapper( int style ) { this.style = style; } /** * Creates the contents. * * @param composite the composite */ public void createContents( final Composite composite ) { // Search Name createSearchNameLine( composite ); // Connection createConnectionLine( composite ); // Search Base createSearchBaseLine( composite ); // Filter createFilterLine( composite ); // Returning Attributes createReturningAttributesLine( composite ); // control createControlComposite( composite ); // scope, limit, alias, referral createOptionsComposite( composite ); } /** * Checks if the given style is active. * * @param requiredStyle the required style to check * * @return true, if the required style is active */ protected boolean isActive( int requiredStyle ) { return ( style & requiredStyle ) != 0; } /** * Creates the search name line. * * @param composite the composite */ protected void createSearchNameLine( final Composite composite ) { if ( isActive( NAME_INVISIBLE ) ) { return; } searchNameLabel = BaseWidgetUtils.createLabel( composite, Messages.getString( "SearchPageWrapper.SearchName" ), 1 ); //$NON-NLS-1$ if ( isActive( NAME_READONLY ) ) { searchNameText = BaseWidgetUtils.createReadonlyText( composite, "", 2 ); //$NON-NLS-1$ } else { searchNameText = BaseWidgetUtils.createText( composite, "", 2 ); //$NON-NLS-1$ } searchNameText.addModifyListener( new ModifyListener() { public void modifyText( ModifyEvent e ) { validate(); } } ); searchNameText.setFocus(); BaseWidgetUtils.createSpacer( composite, 3 ); } /** * Creates the connection line. * * @param composite the composite */ protected void createConnectionLine( final Composite composite ) { if ( isActive( CONNECTION_INVISIBLE ) ) { return; } connectionLabel = BaseWidgetUtils.createLabel( composite, Messages.getString( "SearchPageWrapper.Connection" ), 1 ); //$NON-NLS-1$ browserConnectionWidget = new BrowserConnectionWidget(); browserConnectionWidget.createWidget( composite ); browserConnectionWidget.setEnabled( !isActive( CONNECTION_READONLY ) ); browserConnectionWidget.addWidgetModifyListener( new WidgetModifyListener() { public void widgetModified( WidgetModifyEvent event ) { validate(); } } ); BaseWidgetUtils.createSpacer( composite, 3 ); } /** * Creates the search base line. * * @param composite the composite */ protected void createSearchBaseLine( final Composite composite ) { if ( isActive( SEARCHBASE_INVISIBLE ) ) { return; } searchBaseLabel = BaseWidgetUtils.createLabel( composite, Messages.getString( "SearchPageWrapper.SearchBase" ), 1 ); //$NON-NLS-1$ searchBaseWidget = new EntryWidget(); searchBaseWidget.createWidget( composite ); searchBaseWidget.setEnabled( !isActive( SEARCHBASE_READONLY ) ); searchBaseWidget.addWidgetModifyListener( new WidgetModifyListener() { public void widgetModified( WidgetModifyEvent event ) { validate(); } } ); BaseWidgetUtils.createSpacer( composite, 3 ); } /** * Creates the filter line. * * @param composite the composite */ protected void createFilterLine( final Composite composite ) { if ( isActive( FILTER_INVISIBLE ) ) { return; } filterLabel = BaseWidgetUtils.createLabel( composite, Messages.getString( "SearchPageWrapper.Filter" ), 1 ); //$NON-NLS-1$ filterWidget = new FilterWidget(); filterWidget.createWidget( composite ); filterWidget.setEnabled( !isActive( FILTER_READONLY ) ); filterWidget.addWidgetModifyListener( new WidgetModifyListener() { public void widgetModified( WidgetModifyEvent event ) { validate(); } } ); BaseWidgetUtils.createSpacer( composite, 3 ); } /** * Creates the returning attributes line. * * @param composite the composite */ protected void createReturningAttributesLine( final Composite composite ) { if ( isActive( RETURNINGATTRIBUTES_INVISIBLE ) ) { return; } BaseWidgetUtils.createLabel( composite, Messages.getString( "SearchPageWrapper.ReturningAttributes" ), 1 ); //$NON-NLS-1$ Composite retComposite = BaseWidgetUtils.createColumnContainer( composite, 1, 2 ); returningAttributesWidget = new ReturningAttributesWidget(); returningAttributesWidget.createWidget( retComposite ); returningAttributesWidget.setEnabled( !isActive( RETURNINGATTRIBUTES_READONLY ) ); returningAttributesWidget.addWidgetModifyListener( new WidgetModifyListener() { public void widgetModified( WidgetModifyEvent event ) { validate(); } } ); // special returning attributes options if ( isActive( RETURN_DN_VISIBLE ) || isActive( RETURN_ALLATTRIBUTES_VISIBLE ) || isActive( RETURN_OPERATIONALATTRIBUTES_VISIBLE ) ) { BaseWidgetUtils.createSpacer( composite, 1 ); Composite buttonComposite = BaseWidgetUtils.createColumnContainer( composite, 3, 2 ); if ( isActive( RETURN_DN_VISIBLE ) ) { returnDnButton = BaseWidgetUtils.createCheckbox( buttonComposite, Messages .getString( "SearchPageWrapper.ExportDN" ), 1 ); //$NON-NLS-1$ returnDnButton.addSelectionListener( new SelectionAdapter() { public void widgetSelected( SelectionEvent e ) { validate(); } } ); returnDnButton.setSelection( isActive( RETURN_DN_CHECKED ) ); } if ( isActive( RETURN_ALLATTRIBUTES_VISIBLE ) ) { returnAllAttributesButton = BaseWidgetUtils.createCheckbox( buttonComposite, Messages .getString( "SearchPageWrapper.AllUserAttributes" ), 1 ); //$NON-NLS-1$ returnAllAttributesButton.addSelectionListener( new SelectionAdapter() { public void widgetSelected( SelectionEvent e ) { validate(); } } ); returnAllAttributesButton.setSelection( isActive( RETURN_ALLATTRIBUTES_CHECKED ) ); } if ( isActive( RETURN_OPERATIONALATTRIBUTES_VISIBLE ) ) { returnOperationalAttributesButton = BaseWidgetUtils.createCheckbox( buttonComposite, Messages .getString( "SearchPageWrapper.OperationalAttributes" ), 1 ); //$NON-NLS-1$ returnOperationalAttributesButton.addSelectionListener( new SelectionAdapter() { public void widgetSelected( SelectionEvent e ) { validate(); } } ); returnOperationalAttributesButton.setSelection( isActive( RETURN_OPERATIONALATTRIBUTES_CHECKED ) ); } } BaseWidgetUtils.createSpacer( composite, 3 ); } /** * Creates the options composite, this includes the * scope, limit, alias and referral widgets. * * @param composite the composite */ protected void createOptionsComposite( final Composite composite ) { if ( isActive( OPTIONS_INVISIBLE ) ) { return; } Composite optionsComposite = BaseWidgetUtils.createColumnContainer( composite, 2, 3 ); scopeWidget = new ScopeWidget(); scopeWidget.createWidget( optionsComposite ); scopeWidget.setEnabled( !isActive( SCOPEOPTIONS_READONLY ) ); scopeWidget.addWidgetModifyListener( new WidgetModifyListener() { public void widgetModified( WidgetModifyEvent event ) { validate(); } } ); limitWidget = new LimitWidget(); limitWidget.createWidget( optionsComposite ); limitWidget.setEnabled( !isActive( LIMITOPTIONS_READONLY ) ); limitWidget.addWidgetModifyListener( new WidgetModifyListener() { public void widgetModified( WidgetModifyEvent event ) { validate(); } } ); aliasesDereferencingWidget = new AliasesDereferencingWidget(); aliasesDereferencingWidget.createWidget( optionsComposite ); aliasesDereferencingWidget.setEnabled( !isActive( ALIASOPTIONS_READONLY ) ); aliasesDereferencingWidget.addWidgetModifyListener( new WidgetModifyListener() { public void widgetModified( WidgetModifyEvent event ) { validate(); } } ); referralsHandlingWidget = new ReferralsHandlingWidget(); referralsHandlingWidget.createWidget( optionsComposite, !isActive( REFERRALOPTIONS_FOLLOW_MANUAL_INVISIBLE ) ); referralsHandlingWidget.setEnabled( !isActive( REFERRALOPTIONS_READONLY ) ); referralsHandlingWidget.addWidgetModifyListener( new WidgetModifyListener() { public void widgetModified( WidgetModifyEvent event ) { validate(); } } ); } /** * Creates the control composite. * * @param composite the composite */ protected void createControlComposite( final Composite composite ) { if ( isActive( CONTROLS_INVISIBLE ) ) { return; } Composite controlComposite = BaseWidgetUtils.createColumnContainer( composite, 1, 3 ); controlGroup = BaseWidgetUtils.createGroup( controlComposite, Messages.getString( "SearchPageWrapper.Controls" ), 1 ); //$NON-NLS-1$ // ManageDsaIT control manageDsaItControlButton = BaseWidgetUtils.createCheckbox( controlGroup, Messages .getString( "SearchPageWrapper.ManageDsaIt" ), 1 ); //$NON-NLS-1$ manageDsaItControlButton.setToolTipText( Messages.getString( "SearchPageWrapper.ManageDsaItTooltip" ) ); //$NON-NLS-1$ manageDsaItControlButton.addSelectionListener( new SelectionAdapter() { public void widgetSelected( SelectionEvent e ) { validate(); } } ); // subentries control subentriesControlButton = BaseWidgetUtils.createCheckbox( controlGroup, Messages .getString( "SearchPageWrapper.Subentries" ), 1 ); //$NON-NLS-1$ subentriesControlButton.setToolTipText( Messages.getString( "SearchPageWrapper.SubentriesTooltip" ) ); //$NON-NLS-1$ subentriesControlButton.addSelectionListener( new SelectionAdapter() { public void widgetSelected( SelectionEvent e ) { validate(); } } ); // simple paged results control Composite sprcComposite = BaseWidgetUtils.createColumnContainer( controlGroup, 4, 1 ); pagedSearchControlButton = BaseWidgetUtils.createCheckbox( sprcComposite, Messages .getString( "SearchPageWrapper.PagedSearch" ), 1 ); //$NON-NLS-1$ pagedSearchControlButton.setToolTipText( Messages.getString( "SearchPageWrapper.PagedSearchToolTip" ) ); //$NON-NLS-1$ pagedSearchControlButton.addSelectionListener( new SelectionAdapter() { public void widgetSelected( SelectionEvent e ) { validate(); } } ); pagedSearchControlSizeLabel = BaseWidgetUtils.createLabel( sprcComposite, Messages .getString( "SearchPageWrapper.PageSize" ), 1 ); //$NON-NLS-1$ pagedSearchControlSizeText = BaseWidgetUtils.createText( sprcComposite, "100", 5, 1 ); //$NON-NLS-1$ pagedSearchControlSizeText.addVerifyListener( new VerifyListener() { public void verifyText( VerifyEvent e ) { if ( !e.text.matches( "[0-9]*" ) ) //$NON-NLS-1$ { e.doit = false; } } } ); pagedSearchControlSizeText.addModifyListener( new ModifyListener() { public void modifyText( ModifyEvent e ) { validate(); } } ); pagedSearchControlScrollButton = BaseWidgetUtils.createCheckbox( sprcComposite, Messages .getString( "SearchPageWrapper.ScrollMode" ), 1 ); //$NON-NLS-1$ pagedSearchControlScrollButton.setToolTipText( Messages.getString( "SearchPageWrapper.ScrollModeToolTip" ) ); //$NON-NLS-1$ pagedSearchControlScrollButton.setSelection( true ); pagedSearchControlScrollButton.addSelectionListener( new SelectionAdapter() { public void widgetSelected( SelectionEvent e ) { validate(); } } ); } /** * Validates all elements. */ protected void validate() { if ( browserConnectionWidget.getBrowserConnection() != null ) { if ( searchBaseWidget.getDn() == null || searchBaseWidget.getBrowserConnection() != browserConnectionWidget.getBrowserConnection() ) { searchBaseWidget.setInput( browserConnectionWidget.getBrowserConnection(), null ); } } filterWidget.setBrowserConnection( browserConnectionWidget.getBrowserConnection() ); pagedSearchControlSizeLabel.setEnabled( pagedSearchControlButton.getSelection() ); pagedSearchControlSizeText.setEnabled( pagedSearchControlButton.getSelection() ); pagedSearchControlScrollButton.setEnabled( pagedSearchControlButton.getSelection() ); super.notifyListeners(); } /** * Checks if the DNs should be returned/exported. * * @return true, if DNs should be returnde/exported */ public boolean isReturnDn() { return returnDnButton != null && returnDnButton.getSelection(); } /** * Initializes all search page widgets from the given search. * * @param search the search */ public void loadFromSearch( ISearch search ) { if ( searchNameText != null ) { searchNameText.setText( search.getName() ); } if ( search.getBrowserConnection() != null ) { IBrowserConnection browserConnection = search.getBrowserConnection(); Dn searchBase = search.getSearchBase(); if ( browserConnectionWidget != null ) { browserConnectionWidget.setBrowserConnection( browserConnection ); } if ( searchBase != null ) { searchBaseWidget.setInput( browserConnection, searchBase ); } if ( filterWidget != null ) { filterWidget.setBrowserConnection( browserConnection ); filterWidget.setFilter( search.getFilter() ); } if ( returningAttributesWidget != null ) { returningAttributesWidget.setBrowserConnection( browserConnection ); returningAttributesWidget.setInitialReturningAttributes( search.getReturningAttributes() ); } if ( scopeWidget != null ) { scopeWidget.setScope( search.getScope() ); } if ( limitWidget != null ) { limitWidget.setCountLimit( search.getCountLimit() ); limitWidget.setTimeLimit( search.getTimeLimit() ); } if ( aliasesDereferencingWidget != null ) { aliasesDereferencingWidget.setAliasesDereferencingMethod( search.getAliasesDereferencingMethod() ); } if ( referralsHandlingWidget != null ) { referralsHandlingWidget.setReferralsHandlingMethod( search.getReferralsHandlingMethod() ); } if ( subentriesControlButton != null ) { List<Control> searchControls = search.getControls(); if ( searchControls != null && searchControls.size() > 0 ) { for ( Control c : searchControls ) { if ( c instanceof ManageDsaIT ) { manageDsaItControlButton.setSelection( true ); } else if ( c instanceof Subentries ) { subentriesControlButton.setSelection( true ); } else if ( c instanceof PagedResults ) { pagedSearchControlButton.setSelection( true ); pagedSearchControlSizeText.setText( "" + ( ( PagedResults ) c ).getSize() ); //$NON-NLS-1$ pagedSearchControlScrollButton.setSelection( search.isPagedSearchScrollMode() ); } } } } } } /** * Saves all search pages element to the given search. * * @param search the search * * @return true, if the given search has been modified. */ public boolean saveToSearch( ISearch search ) { boolean searchModified = false; if ( searchNameText != null && !searchNameText.getText().equals( search.getName() ) ) { search.getSearchParameter().setName( searchNameText.getText() ); searchModified = true; } if ( browserConnectionWidget != null && browserConnectionWidget.getBrowserConnection() != null && browserConnectionWidget.getBrowserConnection() != search.getBrowserConnection() ) { search.setBrowserConnection( browserConnectionWidget.getBrowserConnection() ); searchModified = true; } if ( searchBaseWidget != null && searchBaseWidget.getDn() != null && !searchBaseWidget.getDn().equals( search.getSearchBase() ) ) { search.getSearchParameter().setSearchBase( searchBaseWidget.getDn() ); searchModified = true; searchBaseWidget.saveDialogSettings(); } if ( filterWidget != null && filterWidget.getFilter() != null ) { if ( !filterWidget.getFilter().equals( search.getFilter() ) ) { search.getSearchParameter().setFilter( filterWidget.getFilter() ); searchModified = true; } filterWidget.saveDialogSettings(); } if ( returningAttributesWidget != null ) { if ( !Arrays.equals( returningAttributesWidget.getReturningAttributes(), search.getReturningAttributes() ) ) { search.getSearchParameter().setReturningAttributes( returningAttributesWidget.getReturningAttributes() ); searchModified = true; } returningAttributesWidget.saveDialogSettings(); if ( returnAllAttributesButton != null || returnOperationalAttributesButton != null ) { List<String> raList = new ArrayList<String>(); raList.addAll( Arrays.asList( search.getReturningAttributes() ) ); if ( returnAllAttributesButton != null ) { if ( returnAllAttributesButton.getSelection() ) { raList.add( SchemaConstants.ALL_USER_ATTRIBUTES ); } if ( returnAllAttributesButton.getSelection() != isActive( RETURN_ALLATTRIBUTES_CHECKED ) ) { searchModified = true; } } if ( returnOperationalAttributesButton != null ) { if ( returnOperationalAttributesButton.getSelection() ) { Collection<AttributeType> opAtds = SchemaUtils .getOperationalAttributeDescriptions( browserConnectionWidget.getBrowserConnection() .getSchema() ); Collection<String> opAtdNames = SchemaUtils.getNames( opAtds ); raList.addAll( opAtdNames ); raList.add( SchemaConstants.ALL_OPERATIONAL_ATTRIBUTES ); } if ( returnOperationalAttributesButton.getSelection() != isActive( RETURN_OPERATIONALATTRIBUTES_CHECKED ) ) { searchModified = true; } } String[] returningAttributes = raList.toArray( new String[raList.size()] ); search.getSearchParameter().setReturningAttributes( returningAttributes ); } } if ( scopeWidget != null ) { SearchScope scope = scopeWidget.getScope(); if ( scope != search.getScope() ) { search.getSearchParameter().setScope( scope ); searchModified = true; } } if ( limitWidget != null ) { int countLimit = limitWidget.getCountLimit(); int timeLimit = limitWidget.getTimeLimit(); if ( countLimit != search.getCountLimit() ) { search.getSearchParameter().setCountLimit( countLimit ); searchModified = true; } if ( timeLimit != search.getTimeLimit() ) { search.getSearchParameter().setTimeLimit( timeLimit ); searchModified = true; } } if ( aliasesDereferencingWidget != null ) { Connection.AliasDereferencingMethod aliasesDereferencingMethod = aliasesDereferencingWidget .getAliasesDereferencingMethod(); if ( aliasesDereferencingMethod != search.getAliasesDereferencingMethod() ) { search.getSearchParameter().setAliasesDereferencingMethod( aliasesDereferencingMethod ); searchModified = true; } } if ( referralsHandlingWidget != null ) { Connection.ReferralHandlingMethod referralsHandlingMethod = referralsHandlingWidget .getReferralsHandlingMethod(); if ( referralsHandlingMethod != search.getReferralsHandlingMethod() ) { search.getSearchParameter().setReferralsHandlingMethod( referralsHandlingMethod ); searchModified = true; } } if ( subentriesControlButton != null ) { Set<Control> oldControls = new HashSet<>(); oldControls.addAll( search.getSearchParameter().getControls() ); search.getSearchParameter().getControls().clear(); if ( manageDsaItControlButton.getSelection() ) { search.getSearchParameter().getControls().add( Controls.MANAGEDSAIT_CONTROL ); } if ( subentriesControlButton.getSelection() ) { search.getSearchParameter().getControls().add( Controls.SUBENTRIES_CONTROL ); } if ( pagedSearchControlButton.getSelection() ) { int pageSize; try { pageSize = Integer.valueOf( pagedSearchControlSizeText.getText() ); }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
true
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/search/ReferralsHandlingWidget.java
plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/search/ReferralsHandlingWidget.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.ldapbrowser.common.widgets.search; import org.apache.directory.studio.common.ui.widgets.AbstractWidget; import org.apache.directory.studio.common.ui.widgets.BaseWidgetUtils; import org.apache.directory.studio.connection.core.Connection; import org.apache.directory.studio.connection.core.Connection.ReferralHandlingMethod; import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Group; /** * The ReferralsHandlingWidget could be used to select the * referrals handling method. It is composed of a group with * two radio buttons. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class ReferralsHandlingWidget extends AbstractWidget { /** The initial referrals handling method. */ private Connection.ReferralHandlingMethod initialReferralsHandlingMethod; /** The group. */ private Group group; /** The follow manually button. */ private Button followManuallyButton; /** The follow automatically button. */ private Button followAutomaticallyButton; /** The ignore button. */ private Button ignoreButton; /** * Creates a new instance of ReferralsHandlingWidget with the given * referrals handling method. * * @param initialReferralsHandlingMethod the initial referrals handling method */ public ReferralsHandlingWidget( Connection.ReferralHandlingMethod initialReferralsHandlingMethod ) { this.initialReferralsHandlingMethod = initialReferralsHandlingMethod; } /** * Creates a new instance of ReferralsHandlingWidget with initial * referrals handling method {@link Connection.ReferralHandlingMethod.FOLLOW}. */ public ReferralsHandlingWidget() { this.initialReferralsHandlingMethod = Connection.ReferralHandlingMethod.FOLLOW; } /** * Creates the widget. * * @param parent the parent */ public void createWidget( Composite parent, boolean followManuallyVisible ) { group = BaseWidgetUtils.createGroup( parent, Messages.getString( "ReferralsHandlingWidget.ReferralsHandling" ), 1 ); //$NON-NLS-1$ Composite groupComposite = BaseWidgetUtils.createColumnContainer( group, 1, 1 ); if ( followManuallyVisible ) { followManuallyButton = BaseWidgetUtils.createRadiobutton( groupComposite, Messages .getString( "ReferralsHandlingWidget.FollowManually" ), 1 ); //$NON-NLS-1$ followManuallyButton.setToolTipText( Messages.getString( "ReferralsHandlingWidget.FollowManuallyTooltip" ) ); //$NON-NLS-1$ followManuallyButton.addSelectionListener( new SelectionAdapter() { public void widgetSelected( SelectionEvent e ) { notifyListeners(); } } ); } followAutomaticallyButton = BaseWidgetUtils.createRadiobutton( groupComposite, Messages .getString( "ReferralsHandlingWidget.FollowAutomatically" ), 1 ); //$NON-NLS-1$ followAutomaticallyButton.setToolTipText( Messages .getString( "ReferralsHandlingWidget.FollowAutomaticallyTooltip" ) ); //$NON-NLS-1$ followAutomaticallyButton.addSelectionListener( new SelectionAdapter() { public void widgetSelected( SelectionEvent e ) { notifyListeners(); } } ); ignoreButton = BaseWidgetUtils.createRadiobutton( groupComposite, Messages .getString( "ReferralsHandlingWidget.Ignore" ), 1 ); //$NON-NLS-1$ ignoreButton.setToolTipText( Messages.getString( "ReferralsHandlingWidget.IgnoreTooltip" ) ); //$NON-NLS-1$ ignoreButton.addSelectionListener( new SelectionAdapter() { public void widgetSelected( SelectionEvent e ) { notifyListeners(); } } ); setReferralsHandlingMethod( initialReferralsHandlingMethod ); } /** * Sets the referrals handling method. * * @param referralsHandlingMethod the referrals handling method */ public void setReferralsHandlingMethod( Connection.ReferralHandlingMethod referralsHandlingMethod ) { initialReferralsHandlingMethod = referralsHandlingMethod; if ( followManuallyButton == null && referralsHandlingMethod == ReferralHandlingMethod.FOLLOW_MANUALLY ) { // fall-back to FOLLOW if manually button is invisible initialReferralsHandlingMethod = ReferralHandlingMethod.FOLLOW; } if ( followManuallyButton != null ) { followManuallyButton .setSelection( initialReferralsHandlingMethod == Connection.ReferralHandlingMethod.FOLLOW_MANUALLY ); } followAutomaticallyButton .setSelection( initialReferralsHandlingMethod == Connection.ReferralHandlingMethod.FOLLOW ); ignoreButton.setSelection( initialReferralsHandlingMethod == Connection.ReferralHandlingMethod.IGNORE ); } /** * Gets the referrals handling method. * * @return the referrals handling method */ public Connection.ReferralHandlingMethod getReferralsHandlingMethod() { if ( ignoreButton.getSelection() ) { return Connection.ReferralHandlingMethod.IGNORE; } else if ( followAutomaticallyButton.getSelection() ) { return Connection.ReferralHandlingMethod.FOLLOW; } else { return Connection.ReferralHandlingMethod.FOLLOW_MANUALLY; } } /** * Sets the enabled state of the widget. * * @param b true to enable the widget, false to disable the widget */ public void setEnabled( boolean b ) { group.setEnabled( b ); if ( followManuallyButton != null ) { followManuallyButton.setEnabled( b ); } followAutomaticallyButton.setEnabled( b ); ignoreButton.setEnabled( b ); } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/search/ReturningAttributesWidget.java
plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/search/ReturningAttributesWidget.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.ldapbrowser.common.widgets.search; import java.util.ArrayList; import java.util.Collection; import java.util.List; import org.apache.directory.studio.common.ui.HistoryUtils; import org.apache.directory.studio.common.ui.widgets.AbstractWidget; import org.apache.directory.studio.common.ui.widgets.BaseWidgetUtils; import org.apache.directory.studio.ldapbrowser.common.BrowserCommonActivator; import org.apache.directory.studio.ldapbrowser.common.BrowserCommonConstants; import org.apache.directory.studio.ldapbrowser.common.widgets.DialogContentAssistant; import org.apache.directory.studio.ldapbrowser.core.model.IBrowserConnection; import org.apache.directory.studio.ldapbrowser.core.model.schema.SchemaUtils; import org.apache.directory.studio.ldapbrowser.core.utils.Utils; import org.eclipse.jface.text.IDocument; import org.eclipse.swt.events.ModifyEvent; import org.eclipse.swt.events.ModifyListener; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.widgets.Combo; import org.eclipse.swt.widgets.Composite; /** * The ReturningAttributesWidget could be used to enter a list of attribute types * return by an LDAP search. It is composed of a combo with content assist * and a history. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class ReturningAttributesWidget extends AbstractWidget { /** The returning attributes combo. */ private Combo returningAttributesCombo; /** The content assist processor. */ private ReturningAttributesContentAssistProcessor contentAssistProcessor; /** The connection. */ private IBrowserConnection browserConnection; /** The initial returning attributes. */ private String[] initialReturningAttributes; /** * Creates a new instance of ReturningAttributesWidget. * * @param initialReturningAttributes the initial returning attributes * @param browserConnection the browser connection */ public ReturningAttributesWidget( IBrowserConnection browserConnection, String[] initialReturningAttributes ) { this.browserConnection = browserConnection; this.initialReturningAttributes = initialReturningAttributes; } /** * Creates a new instance of ReturningAttributesWidget with no connection * and no initial returning attributes. * */ public ReturningAttributesWidget() { this.browserConnection = null; this.initialReturningAttributes = null; } /** * Creates the widget. * * @param parent the parent */ public void createWidget( Composite parent ) { // Combo returningAttributesCombo = BaseWidgetUtils.createCombo( parent, new String[0], -1, 1 ); GridData gd = new GridData( GridData.FILL_HORIZONTAL ); gd.horizontalSpan = 1; gd.widthHint = 200; returningAttributesCombo.setLayoutData( gd ); // Content assist contentAssistProcessor = new ReturningAttributesContentAssistProcessor( null ); DialogContentAssistant raca = new DialogContentAssistant(); raca.enableAutoInsert( true ); raca.enableAutoActivation( true ); raca.setAutoActivationDelay( 500 ); raca.setContentAssistProcessor( contentAssistProcessor, IDocument.DEFAULT_CONTENT_TYPE ); raca.install( returningAttributesCombo ); // History String[] history = HistoryUtils.load( BrowserCommonActivator.getDefault().getDialogSettings(), BrowserCommonConstants.DIALOGSETTING_KEY_RETURNING_ATTRIBUTES_HISTORY ); for ( int i = 0; i < history.length; i++ ) { history[i] = Utils.arrayToString( stringToArray( history[i] ) ); } returningAttributesCombo.setItems( history ); returningAttributesCombo.setText( Utils.arrayToString( this.initialReturningAttributes ) ); returningAttributesCombo.addModifyListener( new ModifyListener() { public void modifyText( ModifyEvent e ) { notifyListeners(); } } ); setBrowserConnection( browserConnection ); } /** * Sets the browser connection. * * @param browserConnection the browser connection */ public void setBrowserConnection( IBrowserConnection browserConnection ) { this.browserConnection = browserConnection; List<String> proposals = new ArrayList<String>(); if ( browserConnection != null ) { // add attribute types proposals.addAll( SchemaUtils.getNames( browserConnection.getSchema().getAttributeTypeDescriptions() ) ); // add @<object class names> Collection<String> ocNames = SchemaUtils.getNames( browserConnection.getSchema() .getObjectClassDescriptions() ); for ( String ocName : ocNames ) { proposals.add( "@" + ocName ); //$NON-NLS-1$ } proposals.add( "+" ); //$NON-NLS-1$ proposals.add( "*" ); //$NON-NLS-1$ } contentAssistProcessor.setProposals( proposals ); } /** * Sets the initial returning attributes. * * @param initialReturningAttributes the initial returning attributes */ public void setInitialReturningAttributes( String[] initialReturningAttributes ) { this.initialReturningAttributes = initialReturningAttributes; returningAttributesCombo.setText( Utils.arrayToString( initialReturningAttributes ) ); } /** * Sets the enabled state of the widget. * * @param b true to enable the widget, false to disable the widget */ public void setEnabled( boolean b ) { this.returningAttributesCombo.setEnabled( b ); } /** * Gets the returning attributes. * * @return the returning attributes */ public String[] getReturningAttributes() { String s = this.returningAttributesCombo.getText(); return stringToArray( s ); } /** * Saves dialog settings. */ public void saveDialogSettings() { HistoryUtils.save( BrowserCommonActivator.getDefault().getDialogSettings(), BrowserCommonConstants.DIALOGSETTING_KEY_RETURNING_ATTRIBUTES_HISTORY, Utils.arrayToString( getReturningAttributes() ) ); } /** * Sets the focus. */ public void setFocus() { returningAttributesCombo.setFocus(); } /** * Splits the given string into an array. Only the following * characters are kept, all other are used to split the string * and are truncated: * <li>a-z * <li>A-Z * <li>0-9 * <li>- * <li>. (part of numeric OID) * <li>; (attribute option) * <li>_ (some directory servers allow underscore in attribute name) * <li>* (all user attributes) * <li>+ (all operational attributes) * <li>@ * <li>= (range option, DIRSTUDIO-985) * * @param s the string to split * * @return the array with the splitted string, or null */ public static String[] stringToArray( String s ) { if ( s == null ) { return null; } else { List<String> attributeList = new ArrayList<String>(); StringBuffer temp = new StringBuffer(); for ( int i = 0; i < s.length(); i++ ) { char c = s.charAt( i ); if ( ( c >= 'a' && c <= 'z' ) || ( c >= 'A' && c <= 'Z' ) || ( c >= '0' && c <= '9' ) || c == '-' || c == '.' || c == ';' || c == '_' || c == '*' || c == '+' || c == '@' || c == '=' ) { temp.append( c ); } else { if ( temp.length() > 0 ) { attributeList.add( temp.toString() ); temp = new StringBuffer(); } } } if ( temp.length() > 0 ) { attributeList.add( temp.toString() ); } return ( String[] ) attributeList.toArray( new String[attributeList.size()] ); } } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/search/FilterWidgetAutoEditStrategyAdapter.java
plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/search/FilterWidgetAutoEditStrategyAdapter.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.ldapbrowser.common.widgets.search; import java.util.ArrayList; import java.util.List; import org.apache.directory.studio.ldapbrowser.common.filtereditor.FilterAutoEditStrategy; import org.apache.directory.studio.ldapbrowser.common.filtereditor.FilterAutoEditStrategy.AutoEditParameters; import org.apache.directory.studio.ldapbrowser.core.model.filter.parser.LdapFilterParser; import org.eclipse.swt.events.ModifyEvent; import org.eclipse.swt.events.ModifyListener; import org.eclipse.swt.events.VerifyEvent; import org.eclipse.swt.events.VerifyListener; import org.eclipse.swt.graphics.Point; import org.eclipse.swt.widgets.Combo; /** * The FilterWidgetAutoEditStrategyAdapter is used to integrate the {@link FilterAutoEditStrategy} * into an combo field. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class FilterWidgetAutoEditStrategyAdapter { /** The auto edit strategy. */ private FilterAutoEditStrategy autoEditStrategy; /** The combo. */ private Combo combo; /** The old texts. */ private List<String> oldTexts; /** The verify events. */ private List<VerifyEvent> verifyEvents; /** The in apply combo customization flag. */ private boolean inApplyComboCustomization; /** * Creates a new instance of FilterWidgetAutoEditStrategyAdapter. * * @param combo the combo * @param parser the filter parser */ public FilterWidgetAutoEditStrategyAdapter( Combo combo, LdapFilterParser parser ) { this.combo = combo; this.oldTexts = new ArrayList<String>(); this.verifyEvents = new ArrayList<VerifyEvent>(); this.inApplyComboCustomization = false; this.autoEditStrategy = new FilterAutoEditStrategy( parser ); combo.addVerifyListener( new VerifyListener() { public void verifyText( VerifyEvent e ) { prepareComboCustomization( e ); } } ); combo.addModifyListener( new ModifyListener() { public void modifyText( ModifyEvent e ) { applyComboCustomization( e ); } } ); } /** * Prepares combo customization. * * @param e the verify event */ public void prepareComboCustomization( VerifyEvent e ) { if ( !inApplyComboCustomization ) { String oldText = combo.getText(); //parser.parse( oldText ); if ( !oldTexts.isEmpty() ) { oldTexts.clear(); verifyEvents.clear(); } oldTexts.add( oldText ); verifyEvents.add( e ); } } /** * Applies combo customization. * * @param e the modify event */ public void applyComboCustomization( ModifyEvent e ) { if ( !inApplyComboCustomization && !verifyEvents.isEmpty() ) { String oldText = oldTexts.remove( 0 ); VerifyEvent verifyEvent = verifyEvents.remove( 0 ); inApplyComboCustomization = true; // extract modification details String text = verifyEvent.text; int offset = verifyEvent.start <= verifyEvent.end ? verifyEvent.start : verifyEvent.end; int length = verifyEvent.start <= verifyEvent.end ? verifyEvent.end - verifyEvent.start : verifyEvent.start - verifyEvent.end; // apply auto edit strategy AutoEditParameters autoEditParameters = new AutoEditParameters( text, offset, length, -1, true ); autoEditStrategy.customizeAutoEditParameters( oldText, autoEditParameters ); // get current selection Point oldSelection = combo.getSelection(); // compose new text String newText = ""; //$NON-NLS-1$ newText += oldText.substring( 0, autoEditParameters.offset ); newText += autoEditParameters.text; newText += oldText.substring( autoEditParameters.offset + autoEditParameters.length, oldText.length() ); // determine new cursor position Point newSelection; if ( autoEditParameters.caretOffset != -1 ) { int x = autoEditParameters.caretOffset; newSelection = new Point( x, x ); } else { newSelection = new Point( oldSelection.x, oldSelection.y ); } // set new text and cursor position if ( verifyEvents.isEmpty() ) { combo.setText( newText ); combo.setSelection( newSelection ); } inApplyComboCustomization = 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/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/search/Messages.java
plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/search/Messages.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.ldapbrowser.common.widgets.search; import java.util.MissingResourceException; import java.util.ResourceBundle; /** * This class get messages from the resources file. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class Messages { /** The resource name */ private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle.getBundle( Messages.class.getPackage().getName() + ".messages" ); /** * Get back a message from the resource file given a key * * @param key The key associated with the message * @return The found message */ public static String getString( String key ) { try { return RESOURCE_BUNDLE.getString( key ); } catch ( MissingResourceException e ) { return '!' + key + '!'; } } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/search/LimitWidget.java
plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/search/LimitWidget.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.ldapbrowser.common.widgets.search; import org.apache.directory.studio.common.ui.widgets.AbstractWidget; import org.apache.directory.studio.common.ui.widgets.BaseWidgetUtils; import org.eclipse.swt.events.ModifyEvent; import org.eclipse.swt.events.ModifyListener; import org.eclipse.swt.events.VerifyEvent; import org.eclipse.swt.events.VerifyListener; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Group; import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Text; /** * The LimitWidget could be used to select the limits of a connection * or search. It is composed of a group with text input fields. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class LimitWidget extends AbstractWidget { /** The initial count limit. */ private int initialCountLimit; /** The initial time limit. */ private int initialTimeLimit; /** The limit group. */ private Group limitGroup; /** The count limit label. */ private Label countLimitLabel; /** The count limit text. */ private Text countLimitText; /** The time limit label. */ private Label timeLimitLabel; /** The time limit text. */ private Text timeLimitText; /** * Creates a new instance of LimitWidget. * * @param initialTimeLimit the initial time limit * @param initialCountLimit the initial count limit */ public LimitWidget( int initialCountLimit, int initialTimeLimit ) { this.initialCountLimit = initialCountLimit; this.initialTimeLimit = initialTimeLimit; } /** * Creates a new instance of LimitWidget with no limits. */ public LimitWidget() { this.initialCountLimit = 0; this.initialTimeLimit = 0; } /** * Creates the widget. * * @param parent the parent */ public void createWidget( Composite parent ) { limitGroup = BaseWidgetUtils.createGroup( parent, Messages.getString( "LimitWidget.Limits" ), 1 ); //$NON-NLS-1$ GridLayout gl = new GridLayout( 2, false ); limitGroup.setLayout( gl ); // Count limit String countLimitToolTipText = Messages.getString( "LimitWidget.CountLimitTooltip" ); //$NON-NLS-1$ countLimitLabel = BaseWidgetUtils.createLabel( limitGroup, Messages.getString( "LimitWidget.CountLimit" ), 1 ); //$NON-NLS-1$ countLimitLabel.setToolTipText( countLimitToolTipText ); countLimitText = BaseWidgetUtils.createText( limitGroup, "", 1 ); //$NON-NLS-1$ countLimitText.setToolTipText( countLimitToolTipText ); countLimitText.addVerifyListener( new VerifyListener() { public void verifyText( VerifyEvent e ) { if ( !e.text.matches( "[0-9]*" ) ) //$NON-NLS-1$ { e.doit = false; } } } ); countLimitText.addModifyListener( new ModifyListener() { public void modifyText( ModifyEvent e ) { notifyListeners(); } } ); // Time limit String timeLimitToolTipText = Messages.getString( "LimitWidget.TimeLimitToolTip" ); //$NON-NLS-1$ timeLimitLabel = BaseWidgetUtils.createLabel( limitGroup, Messages.getString( "LimitWidget.TimeLimit" ), 1 ); //$NON-NLS-1$ timeLimitLabel.setToolTipText( timeLimitToolTipText ); timeLimitText = BaseWidgetUtils.createText( limitGroup, "", 1 ); //$NON-NLS-1$ timeLimitText.setToolTipText( timeLimitToolTipText ); timeLimitText.addVerifyListener( new VerifyListener() { public void verifyText( VerifyEvent e ) { if ( !e.text.matches( "[0-9]*" ) ) //$NON-NLS-1$ { e.doit = false; } } } ); timeLimitText.addModifyListener( new ModifyListener() { public void modifyText( ModifyEvent e ) { notifyListeners(); } } ); setCountLimit( initialCountLimit ); setTimeLimit( initialTimeLimit ); } /** * Sets the count limit. * * @param countLimit the count limit */ public void setCountLimit( int countLimit ) { initialCountLimit = countLimit; countLimitText.setText( Integer.toString( initialCountLimit ) ); } /** * Sets the time limit. * * @param timeLimit the time limit */ public void setTimeLimit( int timeLimit ) { initialTimeLimit = timeLimit; timeLimitText.setText( Integer.toString( initialTimeLimit ) ); } /** * Gets the count limit. * * @return the count limit */ public int getCountLimit() { int countLimit; try { countLimit = Integer.valueOf( countLimitText.getText() ); } catch ( NumberFormatException e ) { countLimit = 0; } return countLimit; } /** * Gets the time limit. * * @return the time limit */ public int getTimeLimit() { int timeLimit; try { timeLimit = Integer.valueOf( timeLimitText.getText() ); } catch ( NumberFormatException e ) { timeLimit = 0; } return timeLimit; } /** * Sets the enabled state of the widget. * * @param b true to enable the widget, false to disable the widget */ public void setEnabled( boolean b ) { limitGroup.setEnabled( b ); countLimitLabel.setEnabled( b ); countLimitText.setEnabled( b ); timeLimitLabel.setEnabled( b ); timeLimitText.setEnabled( b ); } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/search/ScopeWidget.java
plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/search/ScopeWidget.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.ldapbrowser.common.widgets.search; import org.apache.directory.api.ldap.model.message.SearchScope; import org.apache.directory.studio.common.ui.widgets.AbstractWidget; 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.Group; /** * The ScopeWidget could be used to select the scope of a search. * It is composed of a group with radio buttons. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class ScopeWidget extends AbstractWidget { /** The initial scope. */ private SearchScope initialScope; /** The scope group. */ private Group scopeGroup; /** The scope object button. */ private Button scopeObjectButton; /** The scope onelevel button. */ private Button scopeOnelevelButton; /** The scope subtree button. */ private Button scopeSubtreeButton; /** * Creates a new instance of ScopeWidget with the given * initial scope. * * @param initialScope the initial scope */ public ScopeWidget( SearchScope initialScope ) { this.initialScope = initialScope; } /** * Creates a new instance of ScopeWidget with initial scope * {@link SearchScope.OBJECT}. */ public ScopeWidget() { this.initialScope = SearchScope.OBJECT; } /** * Creates the widget. * * @param parent the parent */ public void createWidget( Composite parent ) { // Scope group scopeGroup = new Group( parent, SWT.NONE ); scopeGroup.setText( Messages.getString( "ScopeWidget.Scope" ) ); //$NON-NLS-1$ scopeGroup.setLayout( new GridLayout( 1, false ) ); scopeGroup.setLayoutData( new GridData( GridData.FILL_BOTH ) ); // Object radio scopeObjectButton = new Button( scopeGroup, SWT.RADIO ); scopeObjectButton.setText( Messages.getString( "ScopeWidget.Object" ) ); //$NON-NLS-1$ scopeObjectButton.addSelectionListener( new SelectionAdapter() { public void widgetSelected( SelectionEvent e ) { notifyListeners(); } } ); // Onelevel radio scopeOnelevelButton = new Button( scopeGroup, SWT.RADIO ); scopeOnelevelButton.setText( Messages.getString( "ScopeWidget.OneLevel" ) ); //$NON-NLS-1$ scopeOnelevelButton.addSelectionListener( new SelectionAdapter() { public void widgetSelected( SelectionEvent e ) { notifyListeners(); } } ); // subtree button scopeSubtreeButton = new Button( scopeGroup, SWT.RADIO ); scopeSubtreeButton.setText( Messages.getString( "ScopeWidget.Subtree" ) ); //$NON-NLS-1$ scopeSubtreeButton.addSelectionListener( new SelectionAdapter() { public void widgetSelected( SelectionEvent e ) { notifyListeners(); } } ); setScope( initialScope ); } /** * Sets the scope. * * @param scope the scope */ public void setScope( SearchScope scope ) { initialScope = scope; scopeObjectButton.setSelection( initialScope == SearchScope.OBJECT ); scopeOnelevelButton.setSelection( initialScope == SearchScope.ONELEVEL ); scopeSubtreeButton.setSelection( initialScope == SearchScope.SUBTREE ); } /** * Gets the scope. * * @return the scope */ public SearchScope getScope() { SearchScope scope; if ( scopeSubtreeButton.getSelection() ) { scope = SearchScope.SUBTREE; } else if ( scopeOnelevelButton.getSelection() ) { scope = SearchScope.ONELEVEL; } else if ( scopeObjectButton.getSelection() ) { scope = SearchScope.OBJECT; } else { scope = SearchScope.ONELEVEL; } return scope; } /** * Sets the enabled state of the widget. * * @param b true to enable the widget, false to disable the widget */ public void setEnabled( boolean b ) { scopeGroup.setEnabled( b ); scopeObjectButton.setEnabled( b ); scopeOnelevelButton.setEnabled( b ); scopeSubtreeButton.setEnabled( b ); } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/search/AliasesDereferencingWidget.java
plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/search/AliasesDereferencingWidget.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.ldapbrowser.common.widgets.search; import org.apache.directory.studio.common.ui.widgets.AbstractWidget; import org.apache.directory.studio.common.ui.widgets.BaseWidgetUtils; import org.apache.directory.studio.connection.core.Connection; import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Group; /** * The AliasesDereferencingWidget could be used to select the * alias dereferencing method. It is composed of a group with * two check boxes. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class AliasesDereferencingWidget extends AbstractWidget { /** The initial aliases dereferencing method */ private Connection.AliasDereferencingMethod initialAliasesDereferencingMethod; /** The group. */ private Group group; /** The finding button. */ private Button findingButton; /** The search button. */ private Button searchButton; /** * Creates a new instance of AliasesDereferencingWidget with the given * dereferencing method. * * @param initialAliasesDereferencingMethod the initial aliases dereferencing method */ public AliasesDereferencingWidget( Connection.AliasDereferencingMethod initialAliasesDereferencingMethod ) { this.initialAliasesDereferencingMethod = initialAliasesDereferencingMethod; } /** * Creates a new instance of AliasesDereferencingWidget. The initial * dereferencing method is set to {@link Connection.AliasDereferencingMethod.ALWAYS}. */ public AliasesDereferencingWidget() { this.initialAliasesDereferencingMethod = Connection.AliasDereferencingMethod.ALWAYS; } /** * Creates the widget. * * @param parent the parent */ public void createWidget( Composite parent ) { group = BaseWidgetUtils.createGroup( parent, Messages .getString( "AliasesDereferencingWidget.AliasesDereferencing" ), 1 ); //$NON-NLS-1$ Composite groupComposite = BaseWidgetUtils.createColumnContainer( group, 1, 1 ); findingButton = BaseWidgetUtils.createCheckbox( groupComposite, Messages .getString( "AliasesDereferencingWidget.FindingBaseDN" ), 1 ); //$NON-NLS-1$ findingButton.addSelectionListener( new SelectionAdapter() { public void widgetSelected( SelectionEvent e ) { notifyListeners(); } } ); searchButton = BaseWidgetUtils.createCheckbox( groupComposite, Messages .getString( "AliasesDereferencingWidget.Search" ), 1 ); //$NON-NLS-1$ searchButton.addSelectionListener( new SelectionAdapter() { public void widgetSelected( SelectionEvent e ) { notifyListeners(); } } ); setAliasesDereferencingMethod( initialAliasesDereferencingMethod ); } /** * Sets the aliases dereferencing method. * * @param aliasesDereferencingMethod the aliases dereferencing method */ public void setAliasesDereferencingMethod( Connection.AliasDereferencingMethod aliasesDereferencingMethod ) { initialAliasesDereferencingMethod = aliasesDereferencingMethod; findingButton.setSelection( initialAliasesDereferencingMethod == Connection.AliasDereferencingMethod.FINDING || initialAliasesDereferencingMethod == Connection.AliasDereferencingMethod.ALWAYS ); searchButton.setSelection( initialAliasesDereferencingMethod == Connection.AliasDereferencingMethod.SEARCH || initialAliasesDereferencingMethod == Connection.AliasDereferencingMethod.ALWAYS ); } /** * Gets the aliases dereferencing method. * * @return the aliases dereferencing method */ public Connection.AliasDereferencingMethod getAliasesDereferencingMethod() { if ( findingButton.getSelection() && searchButton.getSelection() ) { return Connection.AliasDereferencingMethod.ALWAYS; } else if ( findingButton.getSelection() ) { return Connection.AliasDereferencingMethod.FINDING; } else if ( searchButton.getSelection() ) { return Connection.AliasDereferencingMethod.SEARCH; } else { return Connection.AliasDereferencingMethod.NEVER; } } /** * Sets the enabled state of the widget. * * @param b true to enable the widget, false to disable the widget */ public void setEnabled( boolean b ) { group.setEnabled( b ); findingButton.setEnabled( b ); searchButton.setEnabled( b ); } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/search/BrowserConnectionWidget.java
plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/search/BrowserConnectionWidget.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.ldapbrowser.common.widgets.search; import org.apache.directory.studio.common.ui.widgets.AbstractWidget; import org.apache.directory.studio.common.ui.widgets.BaseWidgetUtils; import org.apache.directory.studio.ldapbrowser.common.dialogs.SelectBrowserConnectionDialog; import org.apache.directory.studio.ldapbrowser.core.model.IBrowserConnection; import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Text; /** * The BrowserConnectionWidget could be used to select an {@link IBrowserConnection}. * It is composed of a text to display the selected connection * and a browse button to open a {@link SelectBrowserConnectionDialog}. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class BrowserConnectionWidget extends AbstractWidget { /** The connection text, displays the selected connection */ private Text browserConnectionText; /** The connection browse button, opens the dialog */ private Button connectionBrowseButton; /** The selected connection */ private IBrowserConnection selectedBrowserConnection; /** * Creates a new instance of ConnectionWidget. * * @param connection the initial connection */ public BrowserConnectionWidget( IBrowserConnection connection ) { this.selectedBrowserConnection = connection; } /** * Creates a new instance of ConnectionWidget with no initial connection. */ public BrowserConnectionWidget() { this.selectedBrowserConnection = null; } /** * Creates the widget. * * @param parent the parent */ public void createWidget( final Composite parent ) { // Text browserConnectionText = BaseWidgetUtils.createReadonlyText( parent, "", 1 ); //$NON-NLS-1$ // Button connectionBrowseButton = BaseWidgetUtils.createButton( parent, Messages .getString( "BrowserConnectionWidget.BrowseButton" ), 1 ); //$NON-NLS-1$ connectionBrowseButton.addSelectionListener( new SelectionAdapter() { public void widgetSelected( SelectionEvent e ) { SelectBrowserConnectionDialog dialog = new SelectBrowserConnectionDialog( parent.getShell(), Messages .getString( "BrowserConnectionWidget.SelectConnection" ), selectedBrowserConnection ); //$NON-NLS-1$ dialog.open(); IBrowserConnection browserConnection = dialog.getSelectedBrowserConnection(); if ( browserConnection != null ) { setBrowserConnection( browserConnection ); notifyListeners(); } } } ); // initial values setBrowserConnection( selectedBrowserConnection ); } /** * Gets the selected connection. * * @return the connection */ public IBrowserConnection getBrowserConnection() { return selectedBrowserConnection; } /** * Sets the selected connection. * * @param connection the connection */ public void setBrowserConnection( IBrowserConnection connection ) { selectedBrowserConnection = connection; browserConnectionText.setText( selectedBrowserConnection != null && selectedBrowserConnection.getConnection() != null ? selectedBrowserConnection.getConnection().getName() : "" ); //$NON-NLS-1$ } /** * Sets the enabled state of the widget. * * @param b true to enable the widget, false to disable the widget */ public void setEnabled( boolean b ) { browserConnectionText.setEnabled( b ); connectionBrowseButton.setEnabled( b ); } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/browser/ShowQuickSearchAction.java
plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/browser/ShowQuickSearchAction.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.ldapbrowser.common.widgets.browser; import org.apache.directory.studio.ldapbrowser.common.BrowserCommonActivator; import org.apache.directory.studio.ldapbrowser.common.BrowserCommonConstants; import org.eclipse.jface.action.Action; import org.eclipse.jface.action.IAction; import org.eclipse.ui.texteditor.IWorkbenchActionDefinitionIds; /** * The ShowQuickSearchAction is used to select whether the quick search widget * should be visible in the browser view or not. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class ShowQuickSearchAction extends Action { /** The quick search widget. */ private BrowserQuickSearchWidget quickSearchWidget; /** * Creates a new instance of ShowQuickSearchAction. */ public ShowQuickSearchAction( BrowserQuickSearchWidget quickSearchWidget ) { super( Messages.getString( "ShowQuickSearchAction.ShowQuickSearch" ), IAction.AS_CHECK_BOX ); //$NON-NLS-1$ this.quickSearchWidget = quickSearchWidget; setActionDefinitionId( IWorkbenchActionDefinitionIds.FIND_REPLACE ); setEnabled( true ); setChecked( BrowserCommonActivator.getDefault().getPreferenceStore().getBoolean( BrowserCommonConstants.PREFERENCE_BROWSER_SHOW_QUICK_SEARCH ) ); run(); } /** * {@inheritDoc} */ public void run() { BrowserCommonActivator.getDefault().getPreferenceStore().setValue( BrowserCommonConstants.PREFERENCE_BROWSER_SHOW_QUICK_SEARCH, isChecked() ); if ( quickSearchWidget != null ) { quickSearchWidget.setActive( isChecked() ); } } /** * Disposes this action. */ public void dispose() { quickSearchWidget = 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/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/browser/OpenSortDialogAction.java
plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/browser/OpenSortDialogAction.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.ldapbrowser.common.widgets.browser; import org.apache.directory.studio.ldapbrowser.common.BrowserCommonActivator; import org.apache.directory.studio.ldapbrowser.common.BrowserCommonConstants; import org.eclipse.jface.action.Action; import org.eclipse.ui.PlatformUI; /** * This action opens the {@link BrowserSorterDialog}. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class OpenSortDialogAction extends Action { /** The preferences. */ private BrowserPreferences preferences; /** * Creates a new instance of OpenSortDialogAction. * * @param preferences the preferences */ public OpenSortDialogAction( BrowserPreferences preferences ) { super( Messages.getString( "OpenSortDialogAction.Sorting" ), BrowserCommonActivator.getDefault().getImageDescriptor( BrowserCommonConstants.IMG_SORT ) ); //$NON-NLS-1$ super.setEnabled( true ); this.preferences = preferences; } /** * {@inheritDoc} */ public void run() { BrowserSorterDialog dlg = new BrowserSorterDialog( PlatformUI.getWorkbench().getDisplay().getActiveShell(), preferences ); dlg.open(); } /** * Disposes this action. */ public void dispose() { preferences = 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/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/browser/BrowserWidget.java
plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/browser/BrowserWidget.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.ldapbrowser.common.widgets.browser; import org.apache.directory.studio.common.ui.widgets.BaseWidgetUtils; import org.apache.directory.studio.common.ui.widgets.ViewFormWidget; import org.apache.directory.studio.ldapbrowser.common.dialogs.SelectEntryDialog; import org.eclipse.jface.action.IMenuManager; import org.eclipse.jface.action.IToolBarManager; import org.eclipse.jface.viewers.TreeViewer; import org.eclipse.swt.SWT; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Tree; import org.eclipse.ui.IActionBars; /** * The BrowserWidget is a reusable widget that displays the DIT, searches * and bookmarks of a connection a tree viewer. * It is used by {@link BrowserView} and {@link SelectEntryDialog}. * * It provides a context menu and a local toolbar with actions to * manage entries, searches and bookmarks. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class BrowserWidget extends ViewFormWidget { /** The widget's configuration with the content provider, label provider and menu manager */ private BrowserConfiguration configuration; /** The quick search widget. */ private BrowserQuickSearchWidget quickSearchWidget; /** The action bars. */ private IActionBars actionBars; /** The tree widget used by the tree viewer */ private Tree tree; /** The tree viewer. */ private TreeViewer viewer; /** * Creates a new instance of BrowserWidget. * * @param configuration the configuration * @param actionBars the action bars */ public BrowserWidget( BrowserConfiguration configuration, IActionBars actionBars ) { this.configuration = configuration; this.actionBars = actionBars; } /** * {@inheritDoc} */ public void createWidget( Composite parent ) { if ( actionBars == null ) { super.createWidget( parent ); } else { createContent( parent ); } } /** * {@inheritDoc} */ public IToolBarManager getToolBarManager() { if ( actionBars == null ) { return super.getToolBarManager(); } else { return actionBars.getToolBarManager(); } } /** * {@inheritDoc} */ public IMenuManager getMenuManager() { if ( actionBars == null ) { return super.getMenuManager(); } else { return actionBars.getMenuManager(); } } /** * {@inheritDoc} */ public IMenuManager getContextMenuManager() { if ( actionBars == null ) { return super.getContextMenuManager(); } else { return configuration.getContextMenuManager( viewer ); } } /** * {@inheritDoc} */ protected Control createContent( Composite parent ) { Composite composite = BaseWidgetUtils.createColumnContainer( parent, 1, 1 ); GridLayout gl = new GridLayout( 1, false ); gl.marginHeight = gl.marginWidth = 0; gl.verticalSpacing = gl.horizontalSpacing = 0; composite.setLayout( gl ); GridData gd = new GridData( GridData.FILL_BOTH ); composite.setLayoutData( gd ); quickSearchWidget = new BrowserQuickSearchWidget( this ); quickSearchWidget.createComposite( composite ); // create tree widget and viewer tree = new Tree( composite, SWT.VIRTUAL | SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER ); GridData data = new GridData( GridData.FILL_BOTH ); data.widthHint = 450; data.heightHint = 250; tree.setLayoutData( data ); viewer = new TreeViewer( tree ); viewer.setUseHashlookup( true ); // setup sorter, filter and layout configuration.getSorter().connect( viewer ); configuration.getPreferences().connect( viewer ); // setup providers viewer.setContentProvider( configuration.getContentProvider( this ) ); viewer.setLabelProvider( configuration.getLabelProvider( viewer ) ); return tree; } /** * Sets the input to the tree viewer. * * @param input the input */ public void setInput( Object input ) { viewer.setInput( input ); } /** * Sets focus to the table viewer. */ public void setFocus() { viewer.getTree().setFocus(); } /** * {@inheritDoc} */ public void dispose() { if ( this.viewer != null ) { this.configuration.dispose(); this.configuration = null; if ( quickSearchWidget != null ) { quickSearchWidget.dispose(); quickSearchWidget = null; } this.tree.dispose(); this.tree = null; this.viewer = null; } } /** * Gets the quick search widget. * * @return the quick search widget */ public BrowserQuickSearchWidget getQuickSearchWidget() { return quickSearchWidget; } /** * Gets the tree viewer. * * @return the tree viewer */ public TreeViewer getViewer() { return viewer; } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/browser/BrowserSearchResultPage.java
plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/browser/BrowserSearchResultPage.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.ldapbrowser.common.widgets.browser; import java.util.Arrays; import org.apache.directory.studio.ldapbrowser.core.model.ISearch; import org.apache.directory.studio.ldapbrowser.core.model.ISearchResult; /** * A BrowserSearchResultPage is a container for search results or other nested browser search result pages. * It is used when folding searches with many results. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class BrowserSearchResultPage { /** The tree sorter */ private BrowserSorter sorter; /** The index of the first child search result in this page */ private int first; /** The index of the last child search result in this page */ private int last; /** The parent search */ private ISearch search; /** The parent search result page or null if not nested */ private BrowserSearchResultPage parentSearchResultPage; /** The sub pages */ private BrowserSearchResultPage[] subpages; /** * Creates a new instance of BrowserSearchResultPage. * * @param search the parent search * @param first the index of the first child search result in this page * @param last the index of the last child search result in this page * @param subpages the sub pages * @param sorter the sorter */ public BrowserSearchResultPage( ISearch search, int first, int last, BrowserSearchResultPage[] subpages, BrowserSorter sorter ) { this.search = search; this.first = first; this.last = last; this.subpages = subpages; this.sorter = sorter; if ( subpages != null ) { for ( int i = 0; i < subpages.length; i++ ) { subpages[i].parentSearchResultPage = this; } } } /** * Gets the children, either the sub pages or * the search results contained in this page. * * @return the children */ public Object[] getChildren() { if ( subpages != null ) { return subpages; } else { // 1. get children ISearchResult[] children = search.getSearchResults(); // 2. sort sorter.sort( null, children ); // 3. extract range if ( children != null ) { ISearchResult[] childrenRange = new ISearchResult[last - first + 1]; for ( int i = first; i <= last; i++ ) { childrenRange[i - first] = children[i]; } return childrenRange; } else { return null; } } } /** * Gets the first. * * @return the first */ public int getFirst() { return first; } /** * Gets the last. * * @return the last */ public int getLast() { return last; } /** * Gets the search. * * @return the search */ public ISearch getSearch() { return search; } /** * Gets the parent page if the given search result is contained in this page * or one of the sub pages. * * @param searchResult the search result * * @return the parent page of the given search result. */ public BrowserSearchResultPage getParentOf( ISearchResult searchResult ) { if ( subpages != null ) { BrowserSearchResultPage ep = null; for ( int i = 0; i < subpages.length && ep == null; i++ ) { ep = subpages[i].getParentOf( searchResult ); } return ep; } else { ISearchResult[] sr = ( ISearchResult[] ) getChildren(); if ( sr != null && Arrays.asList( sr ).contains( searchResult ) ) { return this; } else { return null; } } } /** * Gets the direct parent, either a page or the search. * * @return the direct parent */ public Object getParent() { return ( parentSearchResultPage != null ) ? ( Object ) parentSearchResultPage : ( Object ) search; } /** * {@inheritDoc} */ public String toString() { return search.toString() + "[" + first + "..." + last + "]" + hashCode(); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/browser/BrowserPreferences.java
plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/browser/BrowserPreferences.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.ldapbrowser.common.widgets.browser; import org.apache.directory.studio.ldapbrowser.common.BrowserCommonActivator; import org.apache.directory.studio.ldapbrowser.common.BrowserCommonConstants; import org.apache.directory.studio.ldapbrowser.core.BrowserCoreConstants; import org.apache.directory.studio.ldapbrowser.core.BrowserCorePlugin; import org.eclipse.core.runtime.Preferences; import org.eclipse.jface.util.IPropertyChangeListener; import org.eclipse.jface.util.PropertyChangeEvent; import org.eclipse.jface.viewers.TreeViewer; /** * This class is a wrapper for the preferences of the browser widget. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class BrowserPreferences implements IPropertyChangeListener, Preferences.IPropertyChangeListener { /** The tree viewer */ protected TreeViewer viewer; /** * Creates a new instance of BrowserPreferences. */ public BrowserPreferences() { BrowserCommonActivator.getDefault().getPreferenceStore().addPropertyChangeListener( this ); BrowserCorePlugin.getDefault().getPluginPreferences().addPropertyChangeListener( this ); } /** * Connects the tree viewer to this preferences. * * @param viewer the tree viewer */ public void connect( TreeViewer viewer ) { this.viewer = viewer; } /** * Disposes this preferences. */ public void dispose() { BrowserCommonActivator.getDefault().getPreferenceStore().removePropertyChangeListener( this ); BrowserCorePlugin.getDefault().getPluginPreferences().removePropertyChangeListener( this ); viewer = null; } /** * Gets the sort entries by, one of BrowserCoreConstants.SORT_BY_NONE, * BrowserCoreConstants.SORT_BY_RDN or BrowserCoreConstants.SORT_BY_RDN_VALUE. * * @return the sort entries by */ public int getSortEntriesBy() { return BrowserCommonActivator.getDefault().getPreferenceStore().getInt( BrowserCommonConstants.PREFERENCE_BROWSER_SORT_BY ); } /** * Gets the sort entries order, one of one of BrowserCoreConstants.SORT_ORDER_NONE, * BrowserCoreConstants.SORT_ORDER_ASCENDING or BrowserCoreConstants.SORT_ORDER_DESCENDING. * * @return the sort entries order */ public int getSortEntriesOrder() { return BrowserCommonActivator.getDefault().getPreferenceStore().getInt( BrowserCommonConstants.PREFERENCE_BROWSER_SORT_ORDER ); } /** * Gets the searches sort order, one of one of BrowserCoreConstants.SORT_ORDER_NONE, * BrowserCoreConstants.SORT_ORDER_ASCENDING or BrowserCoreConstants.SORT_ORDER_DESCENDING. * * @return the searches sort order */ public int getSortSearchesOrder() { return BrowserCommonActivator.getDefault().getPreferenceStore().getInt( BrowserCommonConstants.PREFERENCE_BROWSER_SORT_SEARCHES_ORDER ); } /** * Gets the bookmarks sort order, one of one of BrowserCoreConstants.SORT_ORDER_NONE, * BrowserCoreConstants.SORT_ORDER_ASCENDING or BrowserCoreConstants.SORT_ORDER_DESCENDING. * * @return the sort order */ public int getSortBookmarksOrder() { return BrowserCommonActivator.getDefault().getPreferenceStore().getInt( BrowserCommonConstants.PREFERENCE_BROWSER_SORT_BOOKMARKS_ORDER ); } /** * Gets the sort limit. * * @return the sort limit */ public int getSortLimit() { return BrowserCommonActivator.getDefault().getPreferenceStore().getInt( BrowserCommonConstants.PREFERENCE_BROWSER_SORT_LIMIT ); } /** * Returns true if leaf entries should be shown before non-leaf entries. * * @return true, if leaf entries should be shown first */ public boolean isLeafEntriesFirst() { return BrowserCommonActivator.getDefault().getPreferenceStore().getBoolean( BrowserCommonConstants.PREFERENCE_BROWSER_LEAF_ENTRIES_FIRST ); } /** * Returns true if container entries should be shown before leaf entries. * * @return true, if container entries should be shown first */ public boolean isContainerEntriesFirst() { return BrowserCommonActivator.getDefault().getPreferenceStore().getBoolean( BrowserCommonConstants.PREFERENCE_BROWSER_CONTAINER_ENTRIES_FIRST ); } /** * Returns true if meta entries should be shown after non-meta entries. * * @return true, if meta entries should be shown first */ public boolean isMetaEntriesLast() { return BrowserCommonActivator.getDefault().getPreferenceStore().getBoolean( BrowserCommonConstants.PREFERENCE_BROWSER_META_ENTRIES_LAST ); } /** * Returns true if the bookmark category should be visible. * * @return true if the bookmark category should be visible */ public boolean isShowBookmarks() { return BrowserCommonActivator.getDefault().getPreferenceStore().getBoolean( BrowserCommonConstants.PREFERENCE_BROWSER_SHOW_BOOKMARKS ); } /** * Returns true if the DIT category should be visible. * * @return true if the DIT category should be visible */ public boolean isShowDIT() { return BrowserCommonActivator.getDefault().getPreferenceStore().getBoolean( BrowserCommonConstants.PREFERENCE_BROWSER_SHOW_DIT ); } /** * Returns true if the searches category should be visible. * * @return true if the searches category should be visible */ public boolean isShowSearches() { return BrowserCommonActivator.getDefault().getPreferenceStore().getBoolean( BrowserCommonConstants.PREFERENCE_BROWSER_SHOW_SEARCHES ); } /** * Gets the folding size. * * @return the folding size */ public int getFoldingSize() { return BrowserCommonActivator.getDefault().getPreferenceStore().getInt( BrowserCommonConstants.PREFERENCE_BROWSER_FOLDING_SIZE ); } /** * Returns true if folding is enabled. * * @return true if folding is enabled */ public boolean isUseFolding() { return BrowserCommonActivator.getDefault().getPreferenceStore().getBoolean( BrowserCommonConstants.PREFERENCE_BROWSER_ENABLE_FOLDING ); } /** * Returns true if meta entries should be visible. * * @return true if meta entries should be visible */ public boolean isShowDirectoryMetaEntries() { return BrowserCommonActivator.getDefault().getPreferenceStore().getBoolean( BrowserCommonConstants.PREFERENCE_BROWSER_SHOW_DIRECTORY_META_ENTRIES ); } /** * Returns true if entry lables should be abbreviated. * * @return true if entry lables should be abbreviated */ public boolean isEntryAbbreviate() { return BrowserCommonActivator.getDefault().getPreferenceStore().getBoolean( BrowserCommonConstants.PREFERENCE_BROWSER_ENTRY_ABBREVIATE ); } /** * Gets the entry's maximum label length. * * @return the entry's maximum label length */ public int getEntryAbbreviateMaxLength() { return BrowserCommonActivator.getDefault().getPreferenceStore().getInt( BrowserCommonConstants.PREFERENCE_BROWSER_ENTRY_ABBREVIATE_MAX_LENGTH ); } /** * Gets the entry label, one of BrowserWidgetsConstants.SHOW_DN, * BrowserWidgetsConstants.SHOW_RDN or BrowserWidgetsConstants.SHOW_RDN_VALUE. * * @return the entry label */ public int getEntryLabel() { return BrowserCommonActivator.getDefault().getPreferenceStore().getInt( BrowserCommonConstants.PREFERENCE_BROWSER_ENTRY_LABEL ); } /** * Returns true if search result lables should be abbreviated. * * @return true if search result lables should be abbreviated */ public boolean isSearchResultAbbreviate() { return BrowserCommonActivator.getDefault().getPreferenceStore().getBoolean( BrowserCommonConstants.PREFERENCE_BROWSER_SEARCH_RESULT_ABBREVIATE ); } /** * Gets the search result's maximum label length. * * @return the search result's maximum label length */ public int getSearchResultAbbreviateMaxLength() { return BrowserCommonActivator.getDefault().getPreferenceStore().getInt( BrowserCommonConstants.PREFERENCE_BROWSER_SEARCH_RESULT_ABBREVIATE_MAX_LENGTH ); } /** * Gets the search result label, one of BrowserWidgetsConstants.SHOW_DN, * BrowserWidgetsConstants.SHOW_RDN or BrowserWidgetsConstants.SHOW_RDN_VALUE. * * @return the entry label */ public int getSearchResultLabel() { return BrowserCommonActivator.getDefault().getPreferenceStore().getInt( BrowserCommonConstants.PREFERENCE_BROWSER_SEARCH_RESULT_LABEL ); } /** * Returns true if the base entries should be expanded when * opening connection. * * @return true if the base entries should be expanded */ public boolean isExpandBaseEntries() { return BrowserCommonActivator.getDefault().getPreferenceStore().getBoolean( BrowserCommonConstants.PREFERENCE_BROWSER_EXPAND_BASE_ENTRIES ); } /** * Returns true if the browser should check for children * while browsing the directory. * * @return true if the browser should check for children */ public boolean isCheckForChildren() { Preferences coreStore = BrowserCorePlugin.getDefault().getPluginPreferences(); return coreStore.getBoolean( BrowserCoreConstants.PREFERENCE_CHECK_FOR_CHILDREN ); } /** * {@inheritDoc} */ public void propertyChange( PropertyChangeEvent event ) { if ( viewer != null ) { viewer.refresh(); } } /** * {@inheritDoc} */ public void propertyChange( org.eclipse.core.runtime.Preferences.PropertyChangeEvent event ) { if ( viewer != null ) { viewer.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/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/browser/BrowserConfiguration.java
plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/browser/BrowserConfiguration.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.ldapbrowser.common.widgets.browser; import org.apache.directory.studio.ldapbrowser.common.BrowserCommonActivator; import org.eclipse.jface.action.IMenuManager; import org.eclipse.jface.action.MenuManager; import org.eclipse.jface.viewers.DecoratingLabelProvider; import org.eclipse.jface.viewers.TreeViewer; import org.eclipse.swt.widgets.Menu; /** * The BrowserConfiguration contains the content provider, the * label provider, the sorter, the context menu manager and the * preferences for the browser widget. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class BrowserConfiguration { /** The disposed flag */ private boolean disposed = false; /** The sorter. */ protected BrowserSorter sorter; /** The preferences. */ protected BrowserPreferences preferences; /** The content provider. */ protected BrowserContentProvider contentProvider; /** The label provider. */ protected BrowserLabelProvider labelProvider; /** The decorating label provider. */ protected DecoratingLabelProvider decoratingLabelProvider; /** The context menu manager. */ protected MenuManager contextMenuManager; /** * Creates a new instance of BrowserConfiguration. */ public BrowserConfiguration() { } /** * Disposes this configuration. */ public void dispose() { if ( !disposed ) { if ( preferences != null ) { preferences.dispose(); preferences = null; } if ( contentProvider != null ) { contentProvider.dispose(); contentProvider = null; } if ( labelProvider != null ) { labelProvider.dispose(); labelProvider = null; decoratingLabelProvider.dispose(); decoratingLabelProvider = null; } if ( contextMenuManager != null ) { contextMenuManager.dispose(); contextMenuManager = null; } disposed = true; } } /** * Gets the context menu manager. * * @param viewer the browser widget's tree viewer * * @return the context menu manager */ public IMenuManager getContextMenuManager( TreeViewer viewer ) { if ( contextMenuManager == null ) { contextMenuManager = new MenuManager(); Menu menu = contextMenuManager.createContextMenu( viewer.getControl() ); viewer.getControl().setMenu( menu ); } return contextMenuManager; } /** * Gets the content provider. * * @param widget the browser widget * * @return the content provider */ public BrowserContentProvider getContentProvider( BrowserWidget widget ) { if ( contentProvider == null ) { contentProvider = new BrowserContentProvider( widget, getPreferences(), getSorter() ); } return contentProvider; } /** * Gets the label provider. * * @param viewer the browser widget's tree viewer * * @return the label provider */ public DecoratingLabelProvider getLabelProvider( TreeViewer viewer ) { if ( labelProvider == null ) { labelProvider = new BrowserLabelProvider( getPreferences() ); decoratingLabelProvider = new DecoratingLabelProvider( labelProvider, BrowserCommonActivator.getDefault() .getWorkbench().getDecoratorManager().getLabelDecorator() ); } return decoratingLabelProvider; } /** * Gets the sorter. * * @return the sorter */ public BrowserSorter getSorter() { if ( sorter == null ) { sorter = new BrowserSorter( getPreferences() ); } return sorter; } /** * Gets the preferences. * * @return the preferences */ public BrowserPreferences getPreferences() { if ( preferences == null ) { preferences = new BrowserPreferences(); } return preferences; } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/browser/BrowserContentProvider.java
plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/browser/BrowserContentProvider.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.ldapbrowser.common.widgets.browser; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; import org.apache.directory.studio.connection.core.jobs.OpenConnectionsRunnable; import org.apache.directory.studio.connection.core.jobs.StudioConnectionRunnableWithProgress; import org.apache.directory.studio.ldapbrowser.core.jobs.InitializeChildrenRunnable; import org.apache.directory.studio.ldapbrowser.core.jobs.SearchRunnable; import org.apache.directory.studio.ldapbrowser.core.jobs.StudioBrowserJob; import org.apache.directory.studio.ldapbrowser.core.model.IBookmark; import org.apache.directory.studio.ldapbrowser.core.model.IBrowserConnection; import org.apache.directory.studio.ldapbrowser.core.model.IContinuation; import org.apache.directory.studio.ldapbrowser.core.model.IContinuation.State; import org.apache.directory.studio.ldapbrowser.core.model.IEntry; import org.apache.directory.studio.ldapbrowser.core.model.IQuickSearch; import org.apache.directory.studio.ldapbrowser.core.model.IRootDSE; import org.apache.directory.studio.ldapbrowser.core.model.ISearch; import org.apache.directory.studio.ldapbrowser.core.model.ISearchResult; import org.apache.directory.studio.ldapbrowser.core.model.impl.DirectoryMetadataEntry; import org.apache.directory.studio.ldapbrowser.core.model.impl.SearchContinuation; import org.eclipse.jface.viewers.ISelectionChangedListener; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jface.viewers.ITreeContentProvider; import org.eclipse.jface.viewers.SelectionChangedEvent; import org.eclipse.jface.viewers.TreeViewer; import org.eclipse.jface.viewers.Viewer; /** * The BrowserContentProvider implements the content provider for * the browser widget. It accepts an IConnection as input. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class BrowserContentProvider implements ITreeContentProvider { /** The viewer. */ private TreeViewer viewer; /** The preferences */ protected BrowserPreferences preferences; /** The sorter */ protected BrowserSorter sorter; /** This map contains the pages for entries with many children (if folding is activated) */ private Map<IEntry, BrowserEntryPage[]> entryToEntryPagesMap; /** This map contains the pages for searches with many results (if folding is activated) */ private Map<ISearch, BrowserSearchResultPage[]> searchToSearchResultPagesMap; /** This map contains the top-level categories for each connection */ private Map<IBrowserConnection, BrowserCategory[]> connectionToCategoriesMap; /** The page listener. */ private ISelectionChangedListener pageListener = new ISelectionChangedListener() { public void selectionChanged( SelectionChangedEvent event ) { IStructuredSelection selection = ( IStructuredSelection ) event.getSelection(); if ( selection.size() == 1 && selection.getFirstElement() instanceof StudioConnectionRunnableWithProgress ) { StudioConnectionRunnableWithProgress runnable = ( StudioConnectionRunnableWithProgress ) selection .getFirstElement(); new StudioBrowserJob( runnable ).execute(); } } }; /** * Creates a new instance of BrowserContentProvider. * * @param viewer the viewer * @param preferences the preferences * @param sorter the sorter */ public BrowserContentProvider( BrowserWidget widget, BrowserPreferences preferences, BrowserSorter sorter ) { this.viewer = widget.getViewer(); this.preferences = preferences; this.sorter = sorter; this.entryToEntryPagesMap = new HashMap<IEntry, BrowserEntryPage[]>(); this.searchToSearchResultPagesMap = new HashMap<ISearch, BrowserSearchResultPage[]>(); this.connectionToCategoriesMap = new HashMap<IBrowserConnection, BrowserCategory[]>(); viewer.addSelectionChangedListener( pageListener ); } /** * {@inheritDoc} */ public void inputChanged( Viewer v, Object oldInput, Object newInput ) { } /** * {@inheritDoc} */ public void dispose() { if ( entryToEntryPagesMap != null ) { entryToEntryPagesMap.clear(); entryToEntryPagesMap = null; } if ( searchToSearchResultPagesMap != null ) { searchToSearchResultPagesMap.clear(); searchToSearchResultPagesMap = null; } if ( connectionToCategoriesMap != null ) { connectionToCategoriesMap.clear(); connectionToCategoriesMap = null; } viewer.removeSelectionChangedListener( pageListener ); } /** * {@inheritDoc} */ public Object[] getElements( Object parent ) { if ( parent instanceof IBrowserConnection ) { IBrowserConnection connection = ( IBrowserConnection ) parent; if ( !connectionToCategoriesMap.containsKey( connection ) ) { BrowserCategory[] categories = new BrowserCategory[3]; categories[0] = new BrowserCategory( BrowserCategory.TYPE_DIT, connection ); categories[1] = new BrowserCategory( BrowserCategory.TYPE_SEARCHES, connection ); categories[2] = new BrowserCategory( BrowserCategory.TYPE_BOOKMARKS, connection ); connectionToCategoriesMap.put( connection, categories ); } BrowserCategory[] categories = connectionToCategoriesMap.get( connection ); List<BrowserCategory> catList = new ArrayList<BrowserCategory>( 3 ); if ( preferences.isShowDIT() ) { catList.add( categories[0] ); } if ( preferences.isShowSearches() ) { catList.add( categories[1] ); } if ( preferences.isShowBookmarks() ) { catList.add( categories[2] ); } return catList.toArray( new BrowserCategory[0] ); } else if ( parent instanceof IEntry[] ) { return ( IEntry[] ) parent; } else { return getChildren( parent ); } } /** * {@inheritDoc} */ public Object getParent( final Object child ) { if ( child instanceof BrowserCategory ) { return ( ( BrowserCategory ) child ).getParent(); } else if ( child instanceof BrowserEntryPage ) { return ( ( BrowserEntryPage ) child ).getParent(); } else if ( child instanceof IEntry ) { IEntry parentEntry = ( ( IEntry ) child ).getParententry(); if ( parentEntry == null ) { if ( connectionToCategoriesMap.get( ( ( IEntry ) child ).getBrowserConnection() ) != null ) { return connectionToCategoriesMap.get( ( ( IEntry ) child ).getBrowserConnection() )[0]; } else { return null; } } else if ( parentEntry.getChildrenCount() <= preferences.getFoldingSize() || !preferences.isUseFolding() ) { return parentEntry; } else { BrowserEntryPage[] entryPages = getEntryPages( parentEntry ); BrowserEntryPage ep = null; for ( int i = 0; i < entryPages.length && ep == null; i++ ) { ep = entryPages[i].getParentOf( ( IEntry ) child ); } return ep; } } else if ( child instanceof BrowserSearchResultPage ) { return ( ( BrowserSearchResultPage ) child ).getParent(); } else if ( child instanceof IQuickSearch ) { IQuickSearch quickSearch = ( ( IQuickSearch ) child ); IEntry entry = quickSearch.getBrowserConnection().getEntryFromCache( quickSearch.getSearchBase() ); return entry; } else if ( child instanceof ISearch ) { ISearch search = ( ( ISearch ) child ); if ( connectionToCategoriesMap.get( search.getBrowserConnection() ) != null ) { return connectionToCategoriesMap.get( search.getBrowserConnection() )[1]; } else { return null; } } else if ( child instanceof ISearchResult ) { ISearch parentSearch = ( ( ISearchResult ) child ).getSearch(); if ( parentSearch == null || parentSearch.getSearchResults().length <= preferences.getFoldingSize() || !preferences.isUseFolding() ) { return parentSearch; } else { BrowserSearchResultPage[] srPages = getSearchResultPages( parentSearch ); BrowserSearchResultPage srp = null; for ( int i = 0; i < srPages.length && srp == null; i++ ) { srp = srPages[i].getParentOf( ( ISearchResult ) child ); } return srp; } } else if ( child instanceof IBookmark ) { IBookmark bookmark = ( ( IBookmark ) child ); if ( connectionToCategoriesMap.get( bookmark.getBrowserConnection() ) != null ) { return connectionToCategoriesMap.get( bookmark.getBrowserConnection() )[2]; } else { return null; } } else { return null; } } /** * {@inheritDoc} */ public Object[] getChildren( Object parent ) { if ( parent instanceof BrowserEntryPage ) { BrowserEntryPage entryPage = ( BrowserEntryPage ) parent; Object[] objects = entryPage.getChildren(); if ( objects == null ) { return new String[] { Messages.getString( "BrowserContentProvider.FetchingEntries" ) }; //$NON-NLS-1$ } else if ( objects instanceof IEntry[] ) { IEntry[] entries = ( IEntry[] ) objects; return entries; } else { return objects; } } else if ( parent instanceof IRootDSE ) { final IRootDSE rootDSE = ( IRootDSE ) parent; if ( !rootDSE.isChildrenInitialized() ) { new StudioBrowserJob( new InitializeChildrenRunnable( false, rootDSE ) ).execute(); return new String[] { Messages.getString( "BrowserContentProvider.FetchingEntries" ) }; //$NON-NLS-1$ } // get base entries List<IEntry> entryList = new ArrayList<IEntry>(); entryList.addAll( Arrays.asList( rootDSE.getChildren() ) ); // remove non-visible entries for ( Iterator<IEntry> it = entryList.iterator(); it.hasNext(); ) { Object o = it.next(); if ( !preferences.isShowDirectoryMetaEntries() && ( o instanceof DirectoryMetadataEntry ) ) { it.remove(); } } return entryList.toArray(); } else if ( parent instanceof IEntry ) { final IEntry parentEntry = ( IEntry ) parent; if ( parentEntry instanceof IContinuation ) { IContinuation continuation = ( IContinuation ) parentEntry; if ( continuation.getState() == State.UNRESOLVED ) { continuation.resolve(); } if ( continuation.getState() == State.CANCELED ) { return new Object[0]; } } List<Object> objects = new ArrayList<Object>(); IQuickSearch quickSearch = getQuickSearchForEntry( parentEntry ); if ( quickSearch != null ) { objects.add( quickSearch ); } if ( !parentEntry.isChildrenInitialized() ) { new StudioBrowserJob( new InitializeChildrenRunnable( false, parentEntry ) ).execute(); return new String[] { Messages.getString( "BrowserContentProvider.FetchingEntries" ) }; //$NON-NLS-1$ } else if ( parentEntry.getChildrenCount() <= preferences.getFoldingSize() || !preferences.isUseFolding() ) { if ( entryToEntryPagesMap.containsKey( parentEntry ) ) { entryToEntryPagesMap.remove( parentEntry ); } IEntry[] results = parentEntry.getChildren(); if ( parentEntry.getTopPageChildrenRunnable() != null ) { objects.add( parentEntry.getTopPageChildrenRunnable() ); } objects.addAll( Arrays.asList( results ) ); if ( parentEntry.getNextPageChildrenRunnable() != null ) { objects.add( parentEntry.getNextPageChildrenRunnable() ); } return objects.toArray(); } else { BrowserEntryPage[] entryPages = getEntryPages( parentEntry ); objects.addAll( Arrays.asList( entryPages ) ); return objects.toArray(); } } else if ( parent instanceof BrowserSearchResultPage ) { BrowserSearchResultPage srPage = ( BrowserSearchResultPage ) parent; Object[] objects = srPage.getChildren(); if ( objects == null ) { return new String[] { Messages.getString( "BrowserContentProvider.FetchingSearchResults" ) }; //$NON-NLS-1$ } else if ( objects instanceof ISearchResult[] ) { ISearchResult[] srs = ( ISearchResult[] ) objects; return srs; } else { return objects; } } else if ( parent instanceof ISearch ) { ISearch search = ( ISearch ) parent; if ( search instanceof IContinuation ) { IContinuation continuation = ( IContinuation ) search; if ( continuation.getState() == State.UNRESOLVED ) { continuation.resolve(); } if ( continuation.getState() == State.CANCELED ) { return new Object[0]; } } if ( search.getSearchResults() == null || search.getSearchContinuations() == null ) { new StudioBrowserJob( new SearchRunnable( new ISearch[] { search } ) ).execute(); return new String[] { Messages.getString( "BrowserContentProvider.PerformingSearch" ) }; //$NON-NLS-1$ } else if ( search.getSearchResults().length + search.getSearchContinuations().length == 0 ) { return new String[] { Messages.getString( "BrowserContentProvider.NoResults" ) }; //$NON-NLS-1$ } else if ( search.getSearchResults().length <= preferences.getFoldingSize() || !preferences.isUseFolding() ) { if ( searchToSearchResultPagesMap.containsKey( search ) ) { searchToSearchResultPagesMap.remove( search ); } ISearchResult[] results = search.getSearchResults(); SearchContinuation[] scs = search.getSearchContinuations(); List<Object> objects = new ArrayList<Object>(); if ( search.getTopSearchRunnable() != null ) { objects.add( search.getTopSearchRunnable() ); } objects.addAll( Arrays.asList( results ) ); if ( scs != null ) { objects.addAll( Arrays.asList( scs ) ); } if ( search.getNextSearchRunnable() != null ) { objects.add( search.getNextSearchRunnable() ); } return objects.toArray(); } else { BrowserSearchResultPage[] srPages = getSearchResultPages( search ); return srPages; } } else if ( parent instanceof BrowserCategory ) { BrowserCategory category = ( BrowserCategory ) parent; IBrowserConnection browserConnection = category.getParent(); switch ( category.getType() ) { case BrowserCategory.TYPE_DIT: { // open connection when expanding DIT if ( browserConnection.getConnection() != null && !browserConnection.getConnection().getConnectionWrapper().isConnected() ) { new StudioBrowserJob( new OpenConnectionsRunnable( browserConnection.getConnection() ) ) .execute(); return new String[] { Messages.getString( "BrowserContentProvider.OpeningConnection" ) }; //$NON-NLS-1$ } return new Object[] { browserConnection.getRootDSE() }; } case BrowserCategory.TYPE_SEARCHES: { return browserConnection.getSearchManager().getSearches().toArray(); } case BrowserCategory.TYPE_BOOKMARKS: { return browserConnection.getBookmarkManager().getBookmarks(); } } return new Object[0]; } else { return new Object[0]; } } /** * {@inheritDoc} */ public boolean hasChildren( Object parent ) { if ( parent instanceof IEntry ) { IEntry parentEntry = ( IEntry ) parent; return parentEntry.hasChildren() || getQuickSearchForEntry( parentEntry ) != null; } else if ( parent instanceof SearchContinuation ) { return true; } else if ( parent instanceof BrowserEntryPage ) { return true; } else if ( parent instanceof BrowserSearchResultPage ) { return true; } else if ( parent instanceof ISearchResult ) { return false; } else if ( parent instanceof ISearch ) { return true; } else if ( parent instanceof BrowserCategory ) { return true; } else { return false; } } private IQuickSearch getQuickSearchForEntry( IEntry parentEntry ) { IQuickSearch quickSearch = parentEntry.getBrowserConnection().getQuickSearch(); if ( quickSearch != null && parentEntry.getDn().equals( quickSearch.getSearchBase() ) ) { return quickSearch; } return null; } private BrowserEntryPage[] getEntryPages( final IEntry parentEntry ) { BrowserEntryPage[] entryPages; if ( !entryToEntryPagesMap.containsKey( parentEntry ) ) { entryPages = getEntryPages( parentEntry, 0, parentEntry.getChildrenCount() - 1 ); entryToEntryPagesMap.put( parentEntry, entryPages ); } else { entryPages = entryToEntryPagesMap.get( parentEntry ); if ( parentEntry.getChildrenCount() - 1 != entryPages[entryPages.length - 1].getLast() ) { entryPages = getEntryPages( parentEntry, 0, parentEntry.getChildrenCount() - 1 ); entryToEntryPagesMap.put( parentEntry, entryPages ); } } return entryPages; } /** * Creates and returns the entry pages for the given entry. The number of pages * depends on the number of entries and the paging size. * * @param entry the parent entry * @param first the index of the first child entry * @param last the index of the last child entry * @return the created entry pages */ private BrowserEntryPage[] getEntryPages( IEntry entry, int first, int last ) { int pagingSize = preferences.getFoldingSize(); int diff = last - first; int factor = diff > 0 ? ( int ) ( Math.log( diff ) / Math.log( pagingSize ) ) : 0; int groupFirst = first; int groupLast = first; BrowserEntryPage[] pages = new BrowserEntryPage[( int ) ( diff / Math.pow( pagingSize, factor ) ) + 1]; for ( int i = 0; i < pages.length; i++ ) { groupFirst = ( int ) ( i * Math.pow( pagingSize, factor ) ) + first; groupLast = ( int ) ( ( i + 1 ) * Math.pow( pagingSize, factor ) ) + first - 1; groupLast = groupLast > last ? last : groupLast; BrowserEntryPage[] subpages = ( factor > 1 ) ? getEntryPages( entry, groupFirst, groupLast ) : null; pages[i] = new BrowserEntryPage( entry, groupFirst, groupLast, subpages, sorter ); } return pages; } private BrowserSearchResultPage[] getSearchResultPages( ISearch search ) { BrowserSearchResultPage[] srPages; if ( !searchToSearchResultPagesMap.containsKey( search ) ) { srPages = getSearchResultPages( search, 0, search.getSearchResults().length - 1 ); searchToSearchResultPagesMap.put( search, srPages ); } else { srPages = searchToSearchResultPagesMap.get( search ); if ( search.getSearchResults().length - 1 != srPages[srPages.length - 1].getLast() ) { srPages = getSearchResultPages( search, 0, search.getSearchResults().length - 1 ); searchToSearchResultPagesMap.put( search, srPages ); } } return srPages; } /** * Creates and returns the search result pages for the given search. The number of pages * depends on the number of search results and the paging size. * * @param search the parent search * @param first the index of the first search result * @param last the index of the last child search result * @return the created search result pages */ private BrowserSearchResultPage[] getSearchResultPages( ISearch search, int first, int last ) { int pagingSize = preferences.getFoldingSize(); int diff = last - first; int factor = diff > 0 ? ( int ) ( Math.log( diff ) / Math.log( pagingSize ) ) : 0; int groupFirst = first; int groupLast = first; BrowserSearchResultPage[] pages = new BrowserSearchResultPage[( int ) ( diff / Math.pow( pagingSize, factor ) ) + 1]; for ( int i = 0; i < pages.length; i++ ) { groupFirst = ( int ) ( i * Math.pow( pagingSize, factor ) ) + first; groupLast = ( int ) ( ( i + 1 ) * Math.pow( pagingSize, factor ) ) + first - 1; groupLast = groupLast > last ? last : groupLast; BrowserSearchResultPage[] subpages = ( factor > 1 ) ? getSearchResultPages( search, groupFirst, groupLast ) : null; pages[i] = new BrowserSearchResultPage( search, groupFirst, groupLast, subpages, sorter ); } return pages; } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/browser/Messages.java
plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/browser/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.ldapbrowser.common.widgets.browser; 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/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/browser/BrowserEntryPage.java
plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/browser/BrowserEntryPage.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.ldapbrowser.common.widgets.browser; import java.util.Arrays; import org.apache.directory.studio.ldapbrowser.core.model.IEntry; /** * A BrowserEntryPage is a container for entries or other nested browser entry pages. * It is used when folding large branches. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class BrowserEntryPage { /** The tree sorter */ private BrowserSorter sorter; /** The index of the first child entry in this page */ private int first; /** The index of the last child entry in this page */ private int last; /** The parent entry */ private IEntry entry; /** The parent entry page or null if not nested */ private BrowserEntryPage parentEntryPage; /** The sub pages */ private BrowserEntryPage[] subpages; /** * Creates a new instance of BrowserEntryPage. * * @param entry the parent entry * @param first the index of the first child entry in this page * @param last the index of the last child entry in this page * @param subpages the sub pages * @param sorter the sorter */ public BrowserEntryPage( IEntry entry, int first, int last, BrowserEntryPage[] subpages, BrowserSorter sorter ) { this.entry = entry; this.first = first; this.last = last; this.subpages = subpages; this.sorter = sorter; if ( subpages != null ) { for ( int i = 0; i < subpages.length; i++ ) { subpages[i].parentEntryPage = this; } } } /** * Gets the children, either the sub pages or * the entries contained in this page. * * @return the children */ public Object[] getChildren() { if ( subpages != null ) { return subpages; } else { // 1. get children IEntry[] children = entry.getChildren(); // 2. sort sorter.sort( null, children ); // 3. extract range if ( children != null ) { IEntry[] childrenRange = new IEntry[last - first + 1]; for ( int i = first; i <= last; i++ ) { childrenRange[i - first] = children[i]; } return childrenRange; } else { return null; } } } /** * Gets the first. * * @return the first */ public int getFirst() { return first; } /** * Gets the last. * * @return the last */ public int getLast() { return last; } /** * Gets the parent entry. * * @return the parent entry */ public IEntry getEntry() { return entry; } /** * Gets the parent page if the given entry is contained in this page * or one of the sub pages. * * @param entry the entry * * @return the parent page of the given entry. */ public BrowserEntryPage getParentOf( IEntry entry ) { if ( subpages != null ) { BrowserEntryPage ep = null; for ( int i = 0; i < subpages.length && ep == null; i++ ) { ep = subpages[i].getParentOf( entry ); } return ep; } else { IEntry[] sr = ( IEntry[] ) getChildren(); if ( sr != null && Arrays.asList( sr ).contains( entry ) ) { return this; } else { return null; } } } /** * Gets the direct parent, either a page or the entry. * * @return the direct parent */ public Object getParent() { return ( parentEntryPage != null ) ? ( Object ) parentEntryPage : ( Object ) entry; } /** * {@inheritDoc} */ public String toString() { return entry.toString() + "[" + first + "..." + last + "]" + hashCode(); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/browser/BrowserSorterDialog.java
plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/browser/BrowserSorterDialog.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.ldapbrowser.common.widgets.browser; import org.apache.directory.studio.common.ui.widgets.BaseWidgetUtils; import org.apache.directory.studio.ldapbrowser.common.BrowserCommonActivator; import org.apache.directory.studio.ldapbrowser.common.BrowserCommonConstants; import org.apache.directory.studio.ldapbrowser.core.BrowserCoreConstants; import org.eclipse.jface.dialogs.Dialog; import org.eclipse.jface.dialogs.IDialogConstants; import org.eclipse.jface.preference.IPreferenceStore; import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.events.VerifyEvent; import org.eclipse.swt.events.VerifyListener; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Combo; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Group; import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.widgets.Text; /** * This class represents the dialog used to change the browser's sort settings. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class BrowserSorterDialog extends Dialog { /** The dialog title. */ public static final String DIALOG_TITLE = Messages.getString( "BrowserSorterDialog.BrowserSorting" ); //$NON-NLS-1$ /** The Constant SORT_BY_NONE. */ public static final String SORT_BY_NONE = Messages.getString( "BrowserSorterDialog.NoSorting" ); //$NON-NLS-1$ /** The Constant SORT_BY_RDN. */ public static final String SORT_BY_RDN = Messages.getString( "BrowserSorterDialog.RDN" ); //$NON-NLS-1$ /** The Constant SORT_BY_RDN_VALUE. */ public static final String SORT_BY_RDN_VALUE = Messages.getString( "BrowserSorterDialog.RDNValue" ); //$NON-NLS-1$ /** The browser preferences. */ private BrowserPreferences preferences; /** The leaf entries first button. */ private Button leafEntriesFirstButton; /** The container entries first button. */ private Button containerEntriesFirstButton; /** The mixed button. */ private Button mixedButton; /** The meta entries last button. */ private Button metaEntriesLastButton; /** The sort entries by combo. */ private Combo sortEntriesByCombo; /** The sort entries ascending button. */ private Button sortEntriesAscendingButton; /** The sort entries descending button. */ private Button sortEntriesDescendingButton; /** The sort searches ascending button. */ private Button sortSearchesAscendingButton; /** The sort searches descending button. */ private Button sortSearchesDescendingButton; /** The sort searches none button. */ private Button sortSearchesNoSortingButton; /** The sort bookmarks ascending button. */ private Button sortBookmarksAscendingButton; /** The sort bookmarks descending button. */ private Button sortBookmarksDescendingButton; /** The sort bookmarks none button. */ private Button sortBookmarksNoSortingButton; /** The sort limit text. */ private Text sortLimitText; /** * Creates a new instance of BrowserSorterDialog. * * @param parentShell the parent shell * @param preferences the browser preferences */ public BrowserSorterDialog( Shell parentShell, BrowserPreferences preferences ) { super( parentShell ); this.preferences = preferences; } /** * {@inheritDoc} * * This implementation calls its super implementation and sets the dialog title. */ protected void configureShell( Shell newShell ) { super.configureShell( newShell ); newShell.setText( DIALOG_TITLE ); } /** * {@inheritDoc} * * This implementation save the changed settings when OK is pressed. */ protected void buttonPressed( int buttonId ) { if ( buttonId == IDialogConstants.OK_ID ) { int sortLimit = preferences.getSortLimit(); try { sortLimit = Integer.parseInt( sortLimitText.getText().trim() ); } catch ( NumberFormatException nfe ) { } IPreferenceStore store = BrowserCommonActivator.getDefault().getPreferenceStore(); store.setValue( BrowserCommonConstants.PREFERENCE_BROWSER_LEAF_ENTRIES_FIRST, leafEntriesFirstButton .getSelection() ); store.setValue( BrowserCommonConstants.PREFERENCE_BROWSER_CONTAINER_ENTRIES_FIRST, containerEntriesFirstButton.getSelection() ); store.setValue( BrowserCommonConstants.PREFERENCE_BROWSER_META_ENTRIES_LAST, metaEntriesLastButton .getSelection() ); store.setValue( BrowserCommonConstants.PREFERENCE_BROWSER_SORT_ORDER, sortEntriesDescendingButton.getSelection() ? BrowserCoreConstants.SORT_ORDER_DESCENDING : BrowserCoreConstants.SORT_ORDER_ASCENDING ); store.setValue( BrowserCommonConstants.PREFERENCE_BROWSER_SORT_BY, sortEntriesByCombo.getSelectionIndex() == 2 ? BrowserCoreConstants.SORT_BY_RDN_VALUE : sortEntriesByCombo .getSelectionIndex() == 1 ? BrowserCoreConstants.SORT_BY_RDN : BrowserCoreConstants.SORT_BY_NONE ); store.setValue( BrowserCommonConstants.PREFERENCE_BROWSER_SORT_LIMIT, sortLimit ); if ( sortSearchesAscendingButton.getSelection() ) { store.setValue( BrowserCommonConstants.PREFERENCE_BROWSER_SORT_SEARCHES_ORDER, BrowserCoreConstants.SORT_ORDER_ASCENDING ); } else if ( sortSearchesDescendingButton.getSelection() ) { store.setValue( BrowserCommonConstants.PREFERENCE_BROWSER_SORT_SEARCHES_ORDER, BrowserCoreConstants.SORT_ORDER_DESCENDING ); } else if ( sortSearchesNoSortingButton.getSelection() ) { store.setValue( BrowserCommonConstants.PREFERENCE_BROWSER_SORT_SEARCHES_ORDER, BrowserCoreConstants.SORT_ORDER_NONE ); } if ( sortBookmarksAscendingButton.getSelection() ) { store.setValue( BrowserCommonConstants.PREFERENCE_BROWSER_SORT_BOOKMARKS_ORDER, BrowserCoreConstants.SORT_ORDER_ASCENDING ); } else if ( sortBookmarksDescendingButton.getSelection() ) { store.setValue( BrowserCommonConstants.PREFERENCE_BROWSER_SORT_BOOKMARKS_ORDER, BrowserCoreConstants.SORT_ORDER_DESCENDING ); } else if ( sortBookmarksNoSortingButton.getSelection() ) { store.setValue( BrowserCommonConstants.PREFERENCE_BROWSER_SORT_BOOKMARKS_ORDER, BrowserCoreConstants.SORT_ORDER_NONE ); } } else { // no changes } super.buttonPressed( buttonId ); } /** * {@inheritDoc} */ protected Control createDialogArea( Composite parent ) { Composite composite = ( Composite ) super.createDialogArea( parent ); GridData gd = new GridData( GridData.FILL_BOTH | GridData.GRAB_HORIZONTAL ); gd.widthHint = convertHorizontalDLUsToPixels( IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH ); composite.setLayoutData( gd ); createGroupEntriesGroup( composite ); createSortEntriesGroup( composite ); createSortSearchesGroup( composite ); createSortBookmarksGroup( composite ); createSortLimitGroup( composite ); applyDialogFont( composite ); return composite; } /** * Creates the group entries group. * * @param composite the parent composite */ private void createGroupEntriesGroup( Composite composite ) { // Group entries group and composite Group groupEntriesGroup = BaseWidgetUtils.createGroup( composite, Messages .getString( "BrowserSorterDialog.GroupEntries" ), 1 ); //$NON-NLS-1$ Composite groupEntriesButtonsComposite = BaseWidgetUtils.createColumnContainer( groupEntriesGroup, 3, 1 ); // Leaf entries first button leafEntriesFirstButton = BaseWidgetUtils.createRadiobutton( groupEntriesButtonsComposite, Messages .getString( "BrowserSorterDialog.LeafEntriesFirst" ), 1 ); //$NON-NLS-1$ leafEntriesFirstButton.setToolTipText( Messages.getString( "BrowserSorterDialog.LeafEntriesFirstToolTip" ) ); //$NON-NLS-1$ leafEntriesFirstButton.setSelection( preferences.isLeafEntriesFirst() ); // Container entries first button containerEntriesFirstButton = BaseWidgetUtils.createRadiobutton( groupEntriesButtonsComposite, Messages .getString( "BrowserSorterDialog.ContainerEntriesFirst" ), 1 ); //$NON-NLS-1$ containerEntriesFirstButton.setToolTipText( Messages .getString( "BrowserSorterDialog.ContainerEntriesFirstToolTip" ) ); //$NON-NLS-1$ containerEntriesFirstButton.setSelection( preferences.isContainerEntriesFirst() ); // Mixed button mixedButton = BaseWidgetUtils.createRadiobutton( groupEntriesButtonsComposite, Messages.getString( "BrowserSorterDialog.Mixed" ), 1 ); //$NON-NLS-1$ mixedButton.setToolTipText( Messages.getString( "BrowserSorterDialog.MixedToolTip" ) ); //$NON-NLS-1$ mixedButton.setSelection( !preferences.isLeafEntriesFirst() && !preferences.isContainerEntriesFirst() ); // Meta entries last button metaEntriesLastButton = BaseWidgetUtils.createCheckbox( groupEntriesGroup, Messages .getString( "BrowserSorterDialog.MetaEntriesLast" ), 1 ); //$NON-NLS-1$ metaEntriesLastButton.setToolTipText( Messages.getString( "BrowserSorterDialog.MetaEntriesLastToolTip" ) ); //$NON-NLS-1$ metaEntriesLastButton.setSelection( preferences.isMetaEntriesLast() ); } /** * Creates the sort entries group. * * @param composite the parent composite */ private void createSortEntriesGroup( Composite composite ) { // Sort entries group and composite Group sortEntriesGroup = BaseWidgetUtils.createGroup( composite, Messages .getString( "BrowserSorterDialog.SortEntries" ), 1 ); //$NON-NLS-1$ Composite sortByComposite = BaseWidgetUtils.createColumnContainer( sortEntriesGroup, 4, 1 ); // Sort entries by combo BaseWidgetUtils.createLabel( sortByComposite, Messages.getString( "BrowserSorterDialog.SortBy" ), 1 ); //$NON-NLS-1$ sortEntriesByCombo = BaseWidgetUtils.createReadonlyCombo( sortByComposite, new String[] { SORT_BY_NONE, SORT_BY_RDN, SORT_BY_RDN_VALUE }, 0, 1 ); sortEntriesByCombo.select( preferences.getSortEntriesBy() == BrowserCoreConstants.SORT_BY_RDN_VALUE ? 2 : preferences .getSortEntriesBy() == BrowserCoreConstants.SORT_BY_RDN ? 1 : 0 ); sortEntriesByCombo.addSelectionListener( new SelectionAdapter() { public void widgetSelected( SelectionEvent e ) { sortEntriesAscendingButton.setEnabled( sortEntriesByCombo.getSelectionIndex() != 0 ); sortEntriesDescendingButton.setEnabled( sortEntriesByCombo.getSelectionIndex() != 0 ); } } ); // Sort entries ascending button sortEntriesAscendingButton = BaseWidgetUtils.createRadiobutton( sortByComposite, Messages .getString( "BrowserSorterDialog.Ascending" ), 1 ); //$NON-NLS-1$ sortEntriesAscendingButton .setSelection( preferences.getSortEntriesOrder() == BrowserCoreConstants.SORT_ORDER_ASCENDING ); sortEntriesAscendingButton.setEnabled( sortEntriesByCombo.getSelectionIndex() != 0 ); // Sort entries descending button sortEntriesDescendingButton = BaseWidgetUtils.createRadiobutton( sortByComposite, Messages .getString( "BrowserSorterDialog.Descending" ), 1 ); //$NON-NLS-1$ sortEntriesDescendingButton .setSelection( preferences.getSortEntriesOrder() == BrowserCoreConstants.SORT_ORDER_DESCENDING ); sortEntriesDescendingButton.setEnabled( sortEntriesByCombo.getSelectionIndex() != 0 ); } /** * Creates the sort searches group. * * @param parent the parent composite */ private void createSortSearchesGroup( Composite parent ) { // Sort searches group and composite Group sortSearchesGroup = BaseWidgetUtils.createGroup( parent, Messages .getString( "BrowserSorterDialog.SortSearches" ), 1 ); //$NON-NLS-1$ Composite sortSearchesComposite = BaseWidgetUtils.createColumnContainer( sortSearchesGroup, 3, 1 ); // Sort searches ascending button sortSearchesAscendingButton = BaseWidgetUtils.createRadiobutton( sortSearchesComposite, Messages .getString( "BrowserSorterDialog.Ascending" ), 1 ); //$NON-NLS-1$ sortSearchesAscendingButton .setSelection( preferences.getSortSearchesOrder() == BrowserCoreConstants.SORT_ORDER_ASCENDING ); // Sort searches descending button sortSearchesDescendingButton = BaseWidgetUtils.createRadiobutton( sortSearchesComposite, Messages .getString( "BrowserSorterDialog.Descending" ), 1 ); //$NON-NLS-1$ sortSearchesDescendingButton .setSelection( preferences.getSortSearchesOrder() == BrowserCoreConstants.SORT_ORDER_DESCENDING ); // Sort searches none button sortSearchesNoSortingButton = BaseWidgetUtils.createRadiobutton( sortSearchesComposite, Messages .getString( "BrowserSorterDialog.NoSorting" ), 1 ); //$NON-NLS-1$ sortSearchesNoSortingButton .setSelection( preferences.getSortSearchesOrder() == BrowserCoreConstants.SORT_ORDER_NONE ); } /** * Creates the sort bookmarks group. * * @param parent the parent composite */ private void createSortBookmarksGroup( Composite parent ) { // Sort bookmarks group and composite Group sortBookmarksGroup = BaseWidgetUtils.createGroup( parent, Messages .getString( "BrowserSorterDialog.SortBookmarks" ), 1 ); //$NON-NLS-1$ Composite sortBookmarksComposite = BaseWidgetUtils.createColumnContainer( sortBookmarksGroup, 3, 1 ); // Sort bookmarks ascending button sortBookmarksAscendingButton = BaseWidgetUtils.createRadiobutton( sortBookmarksComposite, Messages .getString( "BrowserSorterDialog.Ascending" ), 1 ); //$NON-NLS-1$ sortBookmarksAscendingButton .setSelection( preferences.getSortBookmarksOrder() == BrowserCoreConstants.SORT_ORDER_ASCENDING ); // Sort bookmarks descending button sortBookmarksDescendingButton = BaseWidgetUtils.createRadiobutton( sortBookmarksComposite, Messages .getString( "BrowserSorterDialog.Descending" ), 1 ); //$NON-NLS-1$ sortBookmarksDescendingButton .setSelection( preferences.getSortBookmarksOrder() == BrowserCoreConstants.SORT_ORDER_DESCENDING ); // Sort bookmarks none button sortBookmarksNoSortingButton = BaseWidgetUtils.createRadiobutton( sortBookmarksComposite, Messages .getString( "BrowserSorterDialog.NoSorting" ), 1 ); //$NON-NLS-1$ sortBookmarksNoSortingButton .setSelection( preferences.getSortBookmarksOrder() == BrowserCoreConstants.SORT_ORDER_NONE ); } /** * Creates the sort limit group. * * @param composite the parent composite */ private void createSortLimitGroup( Composite composite ) { // Sort limit group and composite Group sortLimitGroup = BaseWidgetUtils.createGroup( composite, Messages .getString( "BrowserSorterDialog.SortLimit" ), 1 ); //$NON-NLS-1$ Composite sortLimitComposite = BaseWidgetUtils.createColumnContainer( sortLimitGroup, 2, 1 ); // Sort limit text String sortLimitTooltip = Messages.getString( "BrowserSorterDialog.SortLimitToolTip" ); //$NON-NLS-1$ Label sortLimitLabel = BaseWidgetUtils.createLabel( sortLimitComposite, Messages .getString( "BrowserSorterDialog.SortLimitColon" ), 1 ); //$NON-NLS-1$ sortLimitLabel.setToolTipText( sortLimitTooltip ); sortLimitText = BaseWidgetUtils.createText( sortLimitComposite, "" + preferences.getSortLimit(), 5, 1 ); //$NON-NLS-1$ sortLimitText.setToolTipText( sortLimitTooltip ); sortLimitText.addVerifyListener( new VerifyListener() { public void verifyText( VerifyEvent e ) { if ( !e.text.matches( "[0-9]*" ) ) //$NON-NLS-1$ { e.doit = 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/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/browser/BrowserQuickSearchWidget.java
plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/browser/BrowserQuickSearchWidget.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.ldapbrowser.common.widgets.browser; import java.util.Arrays; import java.util.Collection; import org.apache.directory.api.ldap.model.message.SearchScope; import org.apache.directory.api.ldap.model.schema.AttributeType; import org.apache.directory.studio.common.ui.HistoryUtils; 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.BrowserCommonActivator; import org.apache.directory.studio.ldapbrowser.common.BrowserCommonConstants; import org.apache.directory.studio.ldapbrowser.common.actions.BrowserSelectionUtils; import org.apache.directory.studio.ldapbrowser.common.widgets.ListContentProposalProvider; import org.apache.directory.studio.ldapbrowser.core.jobs.SearchRunnable; import org.apache.directory.studio.ldapbrowser.core.jobs.StudioBrowserJob; 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.IQuickSearch; import org.apache.directory.studio.ldapbrowser.core.model.ISearch; import org.apache.directory.studio.ldapbrowser.core.model.impl.QuickSearch; import org.apache.directory.studio.ldapbrowser.core.model.schema.SchemaUtils; import org.eclipse.jface.dialogs.IDialogSettings; import org.eclipse.jface.fieldassist.ComboContentAdapter; import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.ISelectionChangedListener; import org.eclipse.jface.viewers.SelectionChangedEvent; import org.eclipse.swt.SWT; import org.eclipse.swt.events.ModifyEvent; import org.eclipse.swt.events.ModifyListener; import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Combo; import org.eclipse.swt.widgets.Composite; /** * The BrowserQuickSearchWidget implements an instant search * for the browser widget. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class BrowserQuickSearchWidget { /** The Constant VALUE_HISTORY_DIALOGSETTING_KEY. */ public static final String VALUE_HISTORY_DIALOGSETTING_KEY = BrowserQuickSearchWidget.class.getName() + ".valueHistory"; //$NON-NLS-1$ /** The Constant ATTRIBUTE_HISTORY_DIALOGSETTING_KEY. */ public static final String ATTRIBUTE_HISTORY_DIALOGSETTING_KEY = BrowserQuickSearchWidget.class.getName() + ".attributeHistory"; //$NON-NLS-1$ /** An empty string array */ private static final String[] EMPTY = new String[0]; /** The browser widget. */ private BrowserWidget browserWidget; /** The parent, used to create the composite. */ private Composite parent; /** The outer composite. */ private Composite composite; /** The inner composite, it is created/destroyed when showing/hiding the quick search. */ private Composite innerComposite; /** The quick search attribute combo. */ private Combo quickSearchAttributeCombo; /** The quick search attribute proposal provider. */ private ListContentProposalProvider quickSearchAttributePP; /** The quick search operator combo. */ private Combo quickSearchOperatorCombo; /** The quick search value combo. */ private Combo quickSearchValueCombo; /** The quick search value proposal provider. */ private ListContentProposalProvider quickSearchValuePP; /** The quick search scope button. */ private Button quickSearchScopeButton; /** The quick search run button. */ private Button quickSearchRunButton; /** Listener that listens for selections of connections */ private ISelectionChangedListener selectionListener = new ISelectionChangedListener() { /** * {@inheritDoc} * * This implementation sets the input when another connection was selected. */ public void selectionChanged( SelectionChangedEvent event ) { setEnabled( getSelectedEntry() != null ); } }; /** * Creates a new instance of BrowserQuickSearchWidget. * * @param browserWidget the browser widget */ public BrowserQuickSearchWidget( BrowserWidget browserWidget ) { this.browserWidget = browserWidget; if ( HistoryUtils.load( BrowserCommonActivator.getDefault().getDialogSettings(), ATTRIBUTE_HISTORY_DIALOGSETTING_KEY ).length == 0 ) { BrowserCommonActivator.getDefault().getDialogSettings().put( ATTRIBUTE_HISTORY_DIALOGSETTING_KEY, new String[] { "cn", //$NON-NLS-1$ "sn", //$NON-NLS-1$ "givenName", //$NON-NLS-1$ "mail", //$NON-NLS-1$ "uid", //$NON-NLS-1$ "description", //$NON-NLS-1$ "o", //$NON-NLS-1$ "ou", //$NON-NLS-1$ "member" //$NON-NLS-1$ } ); } } /** * Creates the outer composite. * * @param parent the parent */ public void createComposite( Composite parent ) { this.parent = parent; composite = BaseWidgetUtils.createColumnContainer( parent, 1, 1 ); GridLayout gl = new GridLayout(); gl.marginHeight = 2; gl.marginWidth = 2; composite.setLayout( gl ); // Setting the default width and height of the composite to 0 GridData compositeGridData = new GridData( SWT.NONE, SWT.NONE, false, false ); compositeGridData.heightHint = 0; compositeGridData.widthHint = 0; composite.setLayoutData( compositeGridData ); innerComposite = null; } /** * Creates the inner composite with its input fields. */ private void create() { this.browserWidget.getViewer().addPostSelectionChangedListener( selectionListener ); IDialogSettings dialogSettings = BrowserCommonActivator.getDefault().getDialogSettings(); // Reseting the layout of the composite to be displayed correctly GridData compositeGridData = new GridData( SWT.FILL, SWT.NONE, true, false ); composite.setLayoutData( compositeGridData ); innerComposite = BaseWidgetUtils.createColumnContainer( composite, 5, 1 ); String[] attributes = HistoryUtils.load( dialogSettings, ATTRIBUTE_HISTORY_DIALOGSETTING_KEY ); quickSearchAttributeCombo = BaseWidgetUtils.createCombo( innerComposite, attributes, -1, 1 ); quickSearchAttributePP = new ListContentProposalProvider( attributes ); new ExtendedContentAssistCommandAdapter( quickSearchAttributeCombo, new ComboContentAdapter(), quickSearchAttributePP, null, null, true ); quickSearchAttributeCombo.addModifyListener( new ModifyListener() { public void modifyText( ModifyEvent e ) { quickSearchRunButton.setEnabled( !"".equals( quickSearchAttributeCombo.getText() ) ); //$NON-NLS-1$ } } ); quickSearchAttributeCombo.addSelectionListener( new SelectionAdapter() { public void widgetDefaultSelected( SelectionEvent e ) { performSearch(); } } ); GridData gd = new GridData( GridData.FILL_HORIZONTAL ); gd.widthHint = 50; quickSearchAttributeCombo.setLayoutData( gd ); String[] operators = new String[] { "=", "!=", "<=", ">=", "~=" }; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ quickSearchOperatorCombo = BaseWidgetUtils.createReadonlyCombo( innerComposite, operators, 0, 1 ); GridData data = new GridData(); quickSearchOperatorCombo.setLayoutData( data ); String[] values = HistoryUtils.load( dialogSettings, VALUE_HISTORY_DIALOGSETTING_KEY ); quickSearchValueCombo = BaseWidgetUtils.createCombo( innerComposite, values, -1, 1 ); quickSearchValuePP = new ListContentProposalProvider( values ); new ExtendedContentAssistCommandAdapter( quickSearchValueCombo, new ComboContentAdapter(), quickSearchValuePP, null, null, true ); quickSearchValueCombo.addSelectionListener( new SelectionAdapter() { public void widgetDefaultSelected( SelectionEvent e ) { performSearch(); } } ); gd = new GridData( GridData.FILL_HORIZONTAL ); gd.widthHint = 50; quickSearchValueCombo.setLayoutData( gd ); quickSearchScopeButton = new Button( innerComposite, SWT.TOGGLE ); quickSearchScopeButton.setToolTipText( Messages.getString( "BrowserQuickSearchWidget.ScopeOneLevelToolTip" ) ); //$NON-NLS-1$ quickSearchScopeButton.setImage( BrowserCommonActivator.getDefault().getImage( BrowserCommonConstants.IMG_SUBTREE ) ); quickSearchScopeButton.setSelection( BrowserCommonActivator.getDefault().getPreferenceStore() .getBoolean( BrowserCommonConstants.PREFERENCE_BROWSER_QUICK_SEARCH_SUBTREE_SCOPE ) ); quickSearchScopeButton.addSelectionListener( new SelectionAdapter() { public void widgetSelected( SelectionEvent e ) { String one = Messages.getString( "BrowserQuickSearchWidget.ScopeOneLevelToolTip" ); //$NON-NLS-1$ String sub = Messages.getString( "BrowserQuickSearchWidget.ScopeSubtreeToolTip" ); //$NON-NLS-1$ boolean selected = quickSearchScopeButton.getSelection(); quickSearchScopeButton.setToolTipText( selected ? sub : one ); BrowserCommonActivator.getDefault().getPreferenceStore() .setValue( BrowserCommonConstants.PREFERENCE_BROWSER_QUICK_SEARCH_SUBTREE_SCOPE, selected ); } } ); quickSearchRunButton = new Button( innerComposite, SWT.PUSH ); quickSearchRunButton.setToolTipText( Messages.getString( "BrowserQuickSearchWidget.RunQuickSearch" ) ); //$NON-NLS-1$ quickSearchRunButton.setImage( BrowserCommonActivator.getDefault().getImage( BrowserCommonConstants.IMG_QUICKSEARCH ) ); quickSearchRunButton.addSelectionListener( new SelectionAdapter() { public void widgetSelected( SelectionEvent e ) { performSearch(); } } ); setEnabled( getSelectedEntry() != null ); composite.layout( true, true ); parent.layout( true, true ); } private void performSearch() { if ( !quickSearchRunButton.isEnabled() ) { return; } IEntry entry = getSelectedEntry(); if ( entry == null ) { return; } IDialogSettings dialogSettings = BrowserCommonActivator.getDefault().getDialogSettings(); HistoryUtils.save( dialogSettings, ATTRIBUTE_HISTORY_DIALOGSETTING_KEY, quickSearchAttributeCombo.getText() ); String[] attributes = HistoryUtils.load( dialogSettings, ATTRIBUTE_HISTORY_DIALOGSETTING_KEY ); quickSearchAttributeCombo.setItems( attributes ); quickSearchAttributeCombo.select( 0 ); HistoryUtils.save( dialogSettings, VALUE_HISTORY_DIALOGSETTING_KEY, quickSearchValueCombo.getText() ); String[] values = HistoryUtils.load( dialogSettings, VALUE_HISTORY_DIALOGSETTING_KEY ); quickSearchValueCombo.setItems( values ); quickSearchValueCombo.select( 0 ); quickSearchValuePP.setProposals( Arrays.asList( values ) ); IBrowserConnection conn = entry.getBrowserConnection(); QuickSearch quickSearch = new QuickSearch( entry, conn ); quickSearch.getSearchParameter().setScope( quickSearchScopeButton.getSelection() ? SearchScope.SUBTREE : SearchScope.ONELEVEL ); StringBuffer filter = new StringBuffer(); filter.append( "(" ); //$NON-NLS-1$ if ( "!=".equals( quickSearchOperatorCombo.getText() ) ) //$NON-NLS-1$ { filter.append( "!(" ); //$NON-NLS-1$ } filter.append( quickSearchAttributeCombo.getText() ); filter .append( Messages.getString( "BrowserQuickSearchWidget.9" ).equals( quickSearchOperatorCombo.getText() ) ? "=" : quickSearchOperatorCombo.getText() ); //$NON-NLS-1$ //$NON-NLS-2$ // only escape '\', '(', ')', and '\u0000' // don't escape '*' to allow substring search String value = quickSearchValueCombo.getText(); value = value.replaceAll( "\\\\", "\\\\5c" ); //$NON-NLS-1$ //$NON-NLS-2$ value = value.replaceAll( "\u0000", "\\\\00" ); //$NON-NLS-1$ //$NON-NLS-2$ value = value.replaceAll( "\\(", "\\\\28" ); //$NON-NLS-1$ //$NON-NLS-2$ value = value.replaceAll( "\\)", "\\\\29" ); //$NON-NLS-1$ //$NON-NLS-2$ filter.append( value ); if ( "!=".equals( quickSearchOperatorCombo.getText() ) ) //$NON-NLS-1$ { filter.append( ")" ); //$NON-NLS-1$ } filter.append( ")" ); //$NON-NLS-1$ quickSearch.getSearchParameter().setFilter( filter.toString() ); // set new quick search conn.setQuickSearch( quickSearch ); // execute quick search new StudioBrowserJob( new SearchRunnable( new ISearch[] { quickSearch } ) ).execute(); } private IEntry getSelectedEntry() { ISelection selection = browserWidget.getViewer().getSelection(); IEntry[] entries = BrowserSelectionUtils.getEntries( selection ); ISearch[] searches = BrowserSelectionUtils.getSearches( selection ); if ( entries != null && entries.length == 1 ) { IEntry entry = entries[0]; return entry; } else if ( searches != null && searches.length == 1 && ( searches[0] instanceof IQuickSearch ) ) { IQuickSearch quickSearch = ( IQuickSearch ) searches[0]; IEntry entry = quickSearch.getSearchBaseEntry(); return entry; } else { return null; } } /** * Destroys the inner widget. */ private void destroy() { browserWidget.getViewer().removePostSelectionChangedListener( selectionListener ); // Reseting the layout of the composite with a width and height set to 0 GridData compositeGridData = new GridData( SWT.NONE, SWT.NONE, false, false ); compositeGridData.heightHint = 0; compositeGridData.widthHint = 0; composite.setLayoutData( compositeGridData ); innerComposite.dispose(); innerComposite = null; composite.layout( true, true ); parent.layout( true, true ); } /** * Disposes this widget. */ public void dispose() { if ( browserWidget != null ) { quickSearchAttributeCombo = null; quickSearchOperatorCombo = null; quickSearchValueCombo = null; quickSearchRunButton = null; innerComposite = null; composite.dispose(); composite = null; parent = null; browserWidget = null; } } /** * Enables or disables this quick search widget. * * @param enabled true to enable this quick search widget, false to disable it */ private void setEnabled( boolean enabled ) { if ( composite != null && !composite.isDisposed() ) { composite.setEnabled( enabled ); } if ( innerComposite != null && !innerComposite.isDisposed() ) { innerComposite.setEnabled( enabled ); quickSearchAttributeCombo.setEnabled( enabled ); quickSearchOperatorCombo.setEnabled( enabled ); quickSearchValueCombo.setEnabled( enabled ); quickSearchScopeButton.setEnabled( enabled ); quickSearchRunButton.setEnabled( enabled && !"".equals( quickSearchAttributeCombo.getText() ) ); //$NON-NLS-1$ if ( !enabled ) { quickSearchAttributeCombo.setToolTipText( null ); quickSearchOperatorCombo.setToolTipText( null ); quickSearchValueCombo.setToolTipText( null ); parent.setToolTipText( Messages.getString( "BrowserQuickSearchWidget.DisabledToolTipText" ) ); //$NON-NLS-1$ } else { quickSearchAttributeCombo.setToolTipText( Messages .getString( "BrowserQuickSearchWidget.SearchAttribute" ) ); //$NON-NLS-1$ quickSearchOperatorCombo .setToolTipText( Messages.getString( "BrowserQuickSearchWidget.SearchOperator" ) ); //$NON-NLS-1$ quickSearchValueCombo.setToolTipText( Messages.getString( "BrowserQuickSearchWidget.SearchValue" ) ); //$NON-NLS-1$ parent.setToolTipText( null ); } } } /** * Activates or deactivates this quick search widget. * * @param visible true to create this quick search widget, false to destroy it */ public void setActive( boolean visible ) { if ( visible && innerComposite == null && composite != null ) { create(); Object input = browserWidget.getViewer().getInput(); if ( input instanceof IBrowserConnection ) { setInput( ( IBrowserConnection ) input ); } else if ( input instanceof IEntry[] ) { setInput( ( ( IEntry[] ) input )[0].getBrowserConnection() ); } quickSearchAttributeCombo.setFocus(); } else if ( !visible && innerComposite != null && composite != null ) { destroy(); browserWidget.getViewer().getTree().setFocus(); } } /** * Sets the input. * * @param connection the new input */ public void setInput( IBrowserConnection connection ) { if ( innerComposite != null && !innerComposite.isDisposed() ) { String[] atdNames; if ( connection != null ) { Collection<AttributeType> atds = connection.getSchema().getAttributeTypeDescriptions(); atdNames = SchemaUtils.getNames( atds ).toArray( EMPTY ); } else { atdNames = EMPTY; setEnabled( false ); } quickSearchAttributePP.setProposals( Arrays.asList( atdNames ) ); } } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/browser/BrowserLabelProvider.java
plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/browser/BrowserLabelProvider.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.ldapbrowser.common.widgets.browser; import java.util.Collection; import org.apache.directory.api.ldap.model.schema.ObjectClass; import org.apache.directory.api.ldap.model.schema.ObjectClassTypeEnum; import org.apache.directory.studio.connection.core.Utils; import org.apache.directory.studio.connection.core.jobs.StudioConnectionRunnableWithProgress; import org.apache.directory.studio.ldapbrowser.common.BrowserCommonActivator; import org.apache.directory.studio.ldapbrowser.common.BrowserCommonConstants; import org.apache.directory.studio.ldapbrowser.core.BrowserCorePlugin; import org.apache.directory.studio.ldapbrowser.core.model.IBookmark; import org.apache.directory.studio.ldapbrowser.core.model.IContinuation; import org.apache.directory.studio.ldapbrowser.core.model.IContinuation.State; import org.apache.directory.studio.ldapbrowser.core.model.IEntry; import org.apache.directory.studio.ldapbrowser.core.model.IQuickSearch; import org.apache.directory.studio.ldapbrowser.core.model.IRootDSE; import org.apache.directory.studio.ldapbrowser.core.model.ISearch; import org.apache.directory.studio.ldapbrowser.core.model.ISearchResult; import org.apache.directory.studio.ldapbrowser.core.model.impl.BaseDNEntry; import org.apache.directory.studio.ldapbrowser.core.model.impl.DirectoryMetadataEntry; import org.apache.directory.studio.ldapbrowser.core.model.impl.SearchContinuation; import org.apache.directory.studio.ldapbrowser.core.model.schema.ObjectClassIconPair; import org.apache.directory.studio.ldapbrowser.core.model.schema.Schema; import org.apache.directory.studio.ldapbrowser.core.model.schema.SchemaUtils; import org.eclipse.jface.viewers.IColorProvider; import org.eclipse.jface.viewers.IFontProvider; import org.eclipse.jface.viewers.LabelProvider; import org.eclipse.swt.graphics.Color; import org.eclipse.swt.graphics.Font; import org.eclipse.swt.graphics.Image; import org.eclipse.ui.ISharedImages; import org.eclipse.ui.PlatformUI; /** * The BrowserLabelProvider implements the label provider for * the browser widget. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class BrowserLabelProvider extends LabelProvider implements IFontProvider, IColorProvider { /** The preferences. */ private BrowserPreferences preferences; /** * Creates a new instance of BrowserLabelProvider. * * @param preferences the preferences */ public BrowserLabelProvider( BrowserPreferences preferences ) { this.preferences = preferences; } /** * {@inheritDoc} */ public String getText( Object obj ) { if ( obj instanceof IEntry ) { IEntry entry = ( IEntry ) obj; StringBuffer append = new StringBuffer(); if ( entry.isChildrenInitialized() && ( entry.getChildrenCount() > 0 ) || entry.getChildrenFilter() != null ) { append.append( " (" ).append( entry.getChildrenCount() ); //$NON-NLS-1$ if ( entry.hasMoreChildren() ) { append.append( "+" ); //$NON-NLS-1$ } if ( entry.getChildrenFilter() != null ) { append.append( ", filtered" ); //$NON-NLS-1$ } append.append( ")" ); //$NON-NLS-1$ } if ( entry instanceof IRootDSE ) { return "Root DSE" + append.toString(); //$NON-NLS-1$ } else if ( entry instanceof IContinuation ) { return entry.getUrl().toString() + append.toString(); } else if ( entry instanceof BaseDNEntry ) { return entry.getDn().getName() + append.toString(); } else if ( entry.hasParententry() ) { String label = ""; //$NON-NLS-1$ if ( preferences.getEntryLabel() == BrowserCommonConstants.SHOW_DN ) { label = entry.getDn().getName(); } else if ( preferences.getEntryLabel() == BrowserCommonConstants.SHOW_RDN ) { label = entry.getRdn().getName(); } else if ( preferences.getEntryLabel() == BrowserCommonConstants.SHOW_RDN_VALUE ) { label = ( String ) entry.getRdn().getName(); } label += append.toString(); if ( preferences.isEntryAbbreviate() && label.length() > preferences.getEntryAbbreviateMaxLength() ) { label = Utils.shorten( label, preferences.getEntryAbbreviateMaxLength() ); } return label; } else { return entry.getDn().getName() + append.toString(); } } else if ( obj instanceof SearchContinuation ) { SearchContinuation sc = ( SearchContinuation ) obj; return sc.getUrl().toString(); } else if ( obj instanceof BrowserEntryPage ) { BrowserEntryPage container = ( BrowserEntryPage ) obj; return "[" + ( container.getFirst() + 1 ) + "..." + ( container.getLast() + 1 ) + "]"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ } else if ( obj instanceof BrowserSearchResultPage ) { BrowserSearchResultPage container = ( BrowserSearchResultPage ) obj; return "[" + ( container.getFirst() + 1 ) + "..." + ( container.getLast() + 1 ) + "]"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ } else if ( obj instanceof ISearch ) { ISearch search = ( ISearch ) obj; ISearchResult[] results = search.getSearchResults(); SearchContinuation[] scs = search.getSearchContinuations(); StringBuffer append = new StringBuffer( search.getName() ); if ( results != null && scs != null ) { append.append( " (" ).append( results.length + scs.length ); //$NON-NLS-1$ if ( search.isCountLimitExceeded() ) { append.append( "+" ); //$NON-NLS-1$ } append.append( ")" ); //$NON-NLS-1$ } return append.toString(); } else if ( obj instanceof IBookmark ) { IBookmark bookmark = ( IBookmark ) obj; return bookmark.getName(); } else if ( obj instanceof ISearchResult ) { ISearchResult sr = ( ISearchResult ) obj; if ( sr.getEntry() instanceof IContinuation ) { return sr.getEntry().getUrl().toString(); } else if ( sr.getEntry().hasParententry() || sr.getEntry() instanceof IRootDSE ) { String label = ""; //$NON-NLS-1$ if ( sr.getEntry() instanceof IRootDSE ) { label = "Root DSE"; //$NON-NLS-1$ } else if ( preferences.getSearchResultLabel() == BrowserCommonConstants.SHOW_DN ) { label = sr.getEntry().getDn().getName(); } else if ( preferences.getSearchResultLabel() == BrowserCommonConstants.SHOW_RDN ) { label = sr.getEntry().getRdn().getName(); } else if ( preferences.getSearchResultLabel() == BrowserCommonConstants.SHOW_RDN_VALUE ) { label = ( String ) sr.getEntry().getRdn().getName(); } if ( preferences.isSearchResultAbbreviate() && label.length() > preferences.getSearchResultAbbreviateMaxLength() ) { label = Utils.shorten( label, preferences.getSearchResultAbbreviateMaxLength() ); } return label; } else { return sr.getEntry().getDn().getName(); } } else if ( obj instanceof StudioConnectionRunnableWithProgress ) { StudioConnectionRunnableWithProgress runnable = ( StudioConnectionRunnableWithProgress ) obj; for ( Object lockedObject : runnable.getLockedObjects() ) { if ( lockedObject instanceof ISearch ) { ISearch search = ( ISearch ) lockedObject; if ( obj == search.getTopSearchRunnable() ) { return Messages.getString( "BrowserLabelProvider.TopPage" ); //$NON-NLS-1$ } else if ( obj == search.getNextSearchRunnable() ) { return Messages.getString( "BrowserLabelProvider.NextPage" ); //$NON-NLS-1$ } } else if ( lockedObject instanceof IEntry ) { IEntry entry = ( IEntry ) lockedObject; if ( obj == entry.getTopPageChildrenRunnable() ) { return Messages.getString( "BrowserLabelProvider.TopPage" ); //$NON-NLS-1$ } else if ( obj == entry.getNextPageChildrenRunnable() ) { return Messages.getString( "BrowserLabelProvider.NextPage" ); //$NON-NLS-1$ } } } return obj.toString(); } else if ( obj instanceof BrowserCategory ) { BrowserCategory category = ( BrowserCategory ) obj; return category.getTitle(); } else if ( obj != null ) { return obj.toString(); } else { return ""; //$NON-NLS-1$ } } /** * {@inheritDoc} */ public Image getImage( Object obj ) { if ( obj instanceof IEntry ) { IEntry entry = ( IEntry ) obj; if ( entry instanceof IRootDSE ) { return BrowserCommonActivator.getDefault().getImage( BrowserCommonConstants.IMG_ENTRY_ROOT ); } else if ( entry instanceof DirectoryMetadataEntry && ( ( DirectoryMetadataEntry ) entry ).isSchemaEntry() ) { return BrowserCommonActivator.getDefault().getImage( BrowserCommonConstants.IMG_BROWSER_SCHEMABROWSEREDITOR ); } else if ( entry.getDn().equals( entry.getBrowserConnection().getSchema().getDn() ) ) { return BrowserCommonActivator.getDefault().getImage( BrowserCommonConstants.IMG_BROWSER_SCHEMABROWSEREDITOR ); } else { return BrowserLabelProvider.getImageByObjectClass( entry ); } } else if ( obj instanceof BrowserEntryPage ) { return PlatformUI.getWorkbench().getSharedImages().getImage( ISharedImages.IMG_OBJ_FOLDER ); } else if ( obj instanceof BrowserSearchResultPage ) { return PlatformUI.getWorkbench().getSharedImages().getImage( ISharedImages.IMG_OBJ_FOLDER ); } else if ( obj instanceof IQuickSearch ) { return BrowserCommonActivator.getDefault().getImage( BrowserCommonConstants.IMG_QUICKSEARCH ); } else if ( obj instanceof ISearch ) { ISearch search = ( ISearch ) obj; if ( search instanceof IContinuation && ( ( IContinuation ) search ).getState() != State.RESOLVED ) { return BrowserCommonActivator.getDefault().getImage( BrowserCommonConstants.IMG_SEARCH_UNPERFORMED ); } else if ( search.getSearchResults() != null ) { return BrowserCommonActivator.getDefault().getImage( BrowserCommonConstants.IMG_SEARCH ); } else { return BrowserCommonActivator.getDefault().getImage( BrowserCommonConstants.IMG_SEARCH_UNPERFORMED ); } } else if ( obj instanceof IBookmark ) { return BrowserCommonActivator.getDefault().getImage( BrowserCommonConstants.IMG_BOOKMARK ); } else if ( obj instanceof ISearchResult ) { ISearchResult sr = ( ISearchResult ) obj; IEntry entry = sr.getEntry(); return BrowserLabelProvider.getImageByObjectClass( entry ); } else if ( obj instanceof StudioConnectionRunnableWithProgress ) { StudioConnectionRunnableWithProgress runnable = ( StudioConnectionRunnableWithProgress ) obj; for ( Object lockedObject : runnable.getLockedObjects() ) { if ( lockedObject instanceof ISearch ) { ISearch search = ( ISearch ) lockedObject; if ( obj == search.getTopSearchRunnable() ) { return BrowserCommonActivator.getDefault().getImage( BrowserCommonConstants.IMG_TOP ); } else if ( obj == search.getNextSearchRunnable() ) { return BrowserCommonActivator.getDefault().getImage( BrowserCommonConstants.IMG_NEXT ); } } else if ( lockedObject instanceof IEntry ) { IEntry entry = ( IEntry ) lockedObject; if ( obj == entry.getTopPageChildrenRunnable() ) { return BrowserCommonActivator.getDefault().getImage( BrowserCommonConstants.IMG_TOP ); } else if ( obj == entry.getNextPageChildrenRunnable() ) { return BrowserCommonActivator.getDefault().getImage( BrowserCommonConstants.IMG_NEXT ); } } } return null; } else if ( obj instanceof BrowserCategory ) { BrowserCategory category = ( BrowserCategory ) obj; if ( category.getType() == BrowserCategory.TYPE_DIT ) { return BrowserCommonActivator.getDefault().getImage( BrowserCommonConstants.IMG_DIT ); } else if ( category.getType() == BrowserCategory.TYPE_SEARCHES ) { return BrowserCommonActivator.getDefault().getImage( BrowserCommonConstants.IMG_SEARCHES ); } else if ( category.getType() == BrowserCategory.TYPE_BOOKMARKS ) { return BrowserCommonActivator.getDefault().getImage( BrowserCommonConstants.IMG_BOOKMARKS ); } else { return null; } } else { // return // Activator.getDefault().getImage("icons/sandglass.gif"); return null; } } /** * Gets the image associated with the entry based * on the value of its 'objectClass' attribute. * * @param entry * the entry * @return * the image associated with then entry */ public static Image getImageByObjectClass( IEntry entry ) { Schema schema = entry.getBrowserConnection().getSchema(); Collection<ObjectClass> ocds = entry.getObjectClassDescriptions(); if ( ocds != null ) { Collection<String> numericOids = SchemaUtils.getNumericOids( ocds ); ObjectClassIconPair[] objectClassIcons = BrowserCorePlugin.getDefault().getCorePreferences() .getObjectClassIcons(); int maxWeight = 0; ObjectClassIconPair maxObjectClassIconPair = null; for ( ObjectClassIconPair objectClassIconPair : objectClassIcons ) { int weight = 0; String[] ocNumericOids = objectClassIconPair.getOcNumericOids(); for ( String ocNumericOid : ocNumericOids ) { if ( numericOids.contains( ocNumericOid ) ) { ObjectClass ocd = schema.getObjectClassDescription( ocNumericOid ); if ( ocd.getType() == ObjectClassTypeEnum.STRUCTURAL ) { weight += 3; } else if ( ocd.getType() == ObjectClassTypeEnum.AUXILIARY ) { weight += 2; } } } if ( weight > maxWeight ) { maxObjectClassIconPair = objectClassIconPair; } } if ( maxObjectClassIconPair != null ) { return BrowserCommonActivator.getDefault().getImage( maxObjectClassIconPair.getIconPath() ); } } return BrowserCommonActivator.getDefault().getImage( BrowserCommonConstants.IMG_ENTRY ); } /** * {@inheritDoc} */ public Font getFont( Object element ) { return null; } /** * {@inheritDoc} */ public Color getForeground( Object element ) { return null; } /** * {@inheritDoc} */ public Color getBackground( Object element ) { 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/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/browser/BrowserUniversalListener.java
plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/browser/BrowserUniversalListener.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.ldapbrowser.common.widgets.browser; import org.apache.directory.studio.connection.core.Connection; import org.apache.directory.studio.connection.core.ConnectionFolder; import org.apache.directory.studio.connection.core.event.ConnectionEventRegistry; import org.apache.directory.studio.connection.core.event.ConnectionUpdateListener; import org.apache.directory.studio.connection.ui.ConnectionUIPlugin; import org.apache.directory.studio.ldapbrowser.common.BrowserCommonActivator; import org.apache.directory.studio.ldapbrowser.core.events.AttributesInitializedEvent; import org.apache.directory.studio.ldapbrowser.core.events.ChildrenInitializedEvent; import org.apache.directory.studio.ldapbrowser.core.events.EntryModificationEvent; import org.apache.directory.studio.ldapbrowser.core.events.EntryUpdateListener; import org.apache.directory.studio.ldapbrowser.core.events.EventRegistry; import org.apache.directory.studio.ldapbrowser.core.events.SearchUpdateEvent; import org.apache.directory.studio.ldapbrowser.core.events.SearchUpdateListener; import org.apache.directory.studio.ldapbrowser.core.events.SearchUpdateEvent.EventDetail; import org.apache.directory.studio.ldapbrowser.core.model.IEntry; import org.apache.directory.studio.ldapbrowser.core.model.IQuickSearch; import org.apache.directory.studio.ldapbrowser.core.model.IRootDSE; import org.apache.directory.studio.ldapbrowser.core.model.ISearch; import org.eclipse.jface.viewers.DoubleClickEvent; import org.eclipse.jface.viewers.IDoubleClickListener; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jface.viewers.ITreeContentProvider; import org.eclipse.jface.viewers.ITreeViewerListener; import org.eclipse.jface.viewers.StructuredSelection; import org.eclipse.jface.viewers.TreeExpansionEvent; import org.eclipse.jface.viewers.TreeViewer; /** * The BrowserUniversalListener manages all events for the browser widget. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class BrowserUniversalListener implements ConnectionUpdateListener, EntryUpdateListener, SearchUpdateListener { /** The browser widget */ protected BrowserWidget widget; /** The tree viewer */ protected TreeViewer viewer; /** The tree viewer listener */ private ITreeViewerListener treeViewerListener = new ITreeViewerListener() { /** * {@inheritDoc} * * This implementation checks if the collapsed entry more children * than currently fetched. If this is the case cached children are * cleared an must be fetched newly when expanding the tree. * * This could happen when first using a search that returns * only some of an entry's children. */ public void treeCollapsed( TreeExpansionEvent event ) { if ( event.getElement() instanceof IEntry ) { IEntry entry = ( IEntry ) event.getElement(); if ( entry.isChildrenInitialized() && entry.hasMoreChildren() && entry.getChildrenCount() < entry.getBrowserConnection().getCountLimit() ) { entry.setChildrenInitialized( false ); } } } /** * {@inheritDoc} */ public void treeExpanded( TreeExpansionEvent event ) { } }; /** The double click listener. */ private IDoubleClickListener doubleClickListener = new IDoubleClickListener() { public void doubleClick( DoubleClickEvent event ) { if ( event.getSelection() instanceof IStructuredSelection ) { Object obj = ( ( IStructuredSelection ) event.getSelection() ).getFirstElement(); if ( viewer.getExpandedState( obj ) ) { viewer.collapseToLevel( obj, 1 ); } else if ( ( ( ITreeContentProvider ) viewer.getContentProvider() ).hasChildren( obj ) ) { viewer.expandToLevel( obj, 1 ); } } } }; /** * Creates a new instance of BrowserUniversalListener. * * @param viewer the tree viewer */ public BrowserUniversalListener( BrowserWidget widget ) { this.widget = widget; this.viewer = widget.getViewer(); viewer.addTreeListener( treeViewerListener ); viewer.addDoubleClickListener( doubleClickListener ); ConnectionEventRegistry.addConnectionUpdateListener( this, ConnectionUIPlugin.getDefault().getEventRunner() ); EventRegistry.addEntryUpdateListener( this, BrowserCommonActivator.getDefault().getEventRunner() ); EventRegistry.addSearchUpdateListener( this, BrowserCommonActivator.getDefault().getEventRunner() ); } /** * Disposes this listener. */ public void dispose() { if ( viewer != null ) { viewer.removeTreeListener( treeViewerListener ); viewer.removeDoubleClickListener( doubleClickListener ); ConnectionEventRegistry.removeConnectionUpdateListener( this ); EventRegistry.removeEntryUpdateListener( this ); EventRegistry.removeSearchUpdateListener( this ); viewer = null; } } /** * @see org.apache.directory.studio.connection.core.event.ConnectionUpdateListener#connectionOpened(org.apache.directory.studio.connection.core.Connection) */ public void connectionOpened( Connection connection ) { viewer.refresh(); } /** * @see org.apache.directory.studio.connection.core.event.ConnectionUpdateListener#connectionClosed(org.apache.directory.studio.connection.core.Connection) */ public void connectionClosed( Connection connection ) { viewer.collapseAll(); } /** * @see org.apache.directory.studio.connection.core.event.ConnectionUpdateListener#connectionUpdated(org.apache.directory.studio.connection.core.Connection) */ public void connectionUpdated( Connection connection ) { viewer.refresh(); } /** * @see org.apache.directory.studio.connection.core.event.ConnectionUpdateListener#connectionAdded(org.apache.directory.studio.connection.core.Connection) */ public void connectionAdded( Connection connection ) { viewer.refresh(); } /** * @see org.apache.directory.studio.connection.core.event.ConnectionUpdateListener#connectionRemoved(org.apache.directory.studio.connection.core.Connection) */ public void connectionRemoved( Connection connection ) { viewer.refresh(); } /** * @see org.apache.directory.studio.connection.core.event.ConnectionUpdateListener#connectionFolderModified(org.apache.directory.studio.connection.core.ConnectionFolder) */ public void connectionFolderModified( ConnectionFolder connectionFolder ) { } /** * @see org.apache.directory.studio.connection.core.event.ConnectionUpdateListener#connectionFolderAdded(org.apache.directory.studio.connection.core.ConnectionFolder) */ public void connectionFolderAdded( ConnectionFolder connectionFolder ) { } /** * @see org.apache.directory.studio.connection.core.event.ConnectionUpdateListener#connectionFolderRemoved(org.apache.directory.studio.connection.core.ConnectionFolder) */ public void connectionFolderRemoved( ConnectionFolder connectionFolder ) { } /** * {@inheritDoc} * * This implementation refreshes the tree. */ public void entryUpdated( EntryModificationEvent event ) { // Don't handle attribute initalization, could cause double // retrieval of children. // // When double-clicking an entry two Jobs/Threads are started: // - InitializeAttributesJob and // - InitializeChildrenJob // If the InitializeAttributesJob is finished first the // AttributesInitializedEvent is fired. If this causes // a refresh of the tree before the children are initialized // another InitializeChildrenJob is executed. if ( event instanceof AttributesInitializedEvent && !( event.getModifiedEntry() instanceof IRootDSE ) ) { return; } if ( event instanceof ChildrenInitializedEvent ) { boolean expandedState = viewer.getExpandedState( event.getModifiedEntry() ); viewer.collapseToLevel( event.getModifiedEntry(), TreeViewer.ALL_LEVELS ); if ( expandedState ) { viewer.expandToLevel( event.getModifiedEntry(), 1 ); } viewer.refresh( event.getModifiedEntry(), true ); } else { viewer.refresh( event.getModifiedEntry(), true ); } } /** * {@inheritDoc} * * This implementation refreshes the tree and selects the search. */ public void searchUpdated( SearchUpdateEvent searchUpdateEvent ) { ISearch search = searchUpdateEvent.getSearch(); if ( ( search instanceof IQuickSearch ) && ( searchUpdateEvent.getDetail() == EventDetail.SEARCH_REMOVED ) ) { if ( search.getBrowserConnection().getQuickSearch() == search ) { search.getBrowserConnection().setQuickSearch( null ); } } viewer.refresh(); if ( ( search instanceof IQuickSearch ) && ( searchUpdateEvent.getDetail() != EventDetail.SEARCH_REMOVED ) ) { viewer.setSelection( new StructuredSelection( search ), true ); viewer.expandToLevel( search, 1 ); } } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/browser/BrowserActionGroup.java
plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/browser/BrowserActionGroup.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.ldapbrowser.common.widgets.browser; import java.util.HashMap; import java.util.Map; import org.apache.directory.studio.connection.ui.actions.CollapseAllAction; import org.apache.directory.studio.ldapbrowser.common.BrowserCommonConstants; import org.apache.directory.studio.ldapbrowser.common.actions.FilterChildrenAction; import org.apache.directory.studio.ldapbrowser.common.actions.OpenQuickSearchAction; import org.apache.directory.studio.ldapbrowser.common.actions.PropertiesAction; import org.apache.directory.studio.ldapbrowser.common.actions.RefreshAction; import org.apache.directory.studio.ldapbrowser.common.actions.UnfilterChildrenAction; import org.apache.directory.studio.ldapbrowser.common.actions.UpAction; import org.apache.directory.studio.ldapbrowser.common.actions.proxy.ActionHandlerManager; import org.apache.directory.studio.ldapbrowser.common.actions.proxy.BrowserViewActionProxy; import org.apache.directory.studio.ldapbrowser.core.model.IBrowserConnection; import org.apache.directory.studio.utils.ActionUtils; import org.eclipse.jface.action.IAction; import org.eclipse.jface.action.IMenuListener; import org.eclipse.jface.action.IMenuManager; import org.eclipse.jface.action.IToolBarManager; import org.eclipse.jface.action.Separator; import org.eclipse.jface.viewers.TreeViewer; import org.eclipse.ui.IActionBars; import org.eclipse.ui.IWorkbenchActionConstants; import org.eclipse.ui.actions.ActionFactory; /** * This class manages all the actions of the browser widget. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class BrowserActionGroup implements ActionHandlerManager, IMenuListener { /** The open sort dialog action. */ protected OpenSortDialogAction openSortDialogAction; /** The show quick search action. */ protected ShowQuickSearchAction showQuickSearchAction; /** The collapse all action. */ protected CollapseAllAction collapseAllAction; /** The Constant upAction. */ protected static final String UP_ACTION = "upAction"; //$NON-NLS-1$ /** The Constant refreshAction. */ protected static final String REFRESH_ACTION = "refreshAction"; //$NON-NLS-1$ /** The Constant filterChildrenAction. */ protected static final String FILTER_CHILDREN_ACTION = "filterChildrenAction"; //$NON-NLS-1$ /** The Constant openQuickSearchAction. */ protected static final String OPEN_QUICK_SEARCH_ACTION = "openQuickSearch"; //$NON-NLS-1$ /** The Constant unfilterChildrenAction. */ protected static final String UNFILTER_CHILDREN_ACTION = "unfilterChildrenAction"; //$NON-NLS-1$ /** The Constant propertyDialogAction. */ protected static final String PROPERTY_DIALOG_ACTION = "propertyDialogAction"; //$NON-NLS-1$ /** The browser action map. */ protected Map<String, BrowserViewActionProxy> browserActionMap; /** The action bars. */ protected IActionBars actionBars; /** The browser's main widget. */ protected BrowserWidget mainWidget; /** * Creates a new instance of BrowserActionGroup. * * @param mainWidget the browser's main widget * @param configuration the browser's configuration */ public BrowserActionGroup( BrowserWidget mainWidget, BrowserConfiguration configuration ) { this.mainWidget = mainWidget; this.browserActionMap = new HashMap<String, BrowserViewActionProxy>(); TreeViewer viewer = mainWidget.getViewer(); openSortDialogAction = new OpenSortDialogAction( configuration.getPreferences() ); showQuickSearchAction = new ShowQuickSearchAction( mainWidget.getQuickSearchWidget() ); collapseAllAction = new CollapseAllAction( viewer ); browserActionMap.put( OPEN_QUICK_SEARCH_ACTION, new BrowserViewActionProxy( viewer, new OpenQuickSearchAction() ) ); browserActionMap.put( UP_ACTION, new BrowserViewActionProxy( viewer, new UpAction( viewer ) ) ); browserActionMap.put( REFRESH_ACTION, new BrowserViewActionProxy( viewer, new RefreshAction() ) ); browserActionMap.put( FILTER_CHILDREN_ACTION, new BrowserViewActionProxy( viewer, new FilterChildrenAction() ) ); browserActionMap .put( UNFILTER_CHILDREN_ACTION, new BrowserViewActionProxy( viewer, new UnfilterChildrenAction() ) ); browserActionMap.put( PROPERTY_DIALOG_ACTION, new BrowserViewActionProxy( viewer, new PropertiesAction() ) ); } /** * Disposes this action group. */ public void dispose() { if ( mainWidget != null ) { openSortDialogAction.dispose(); openSortDialogAction = null; showQuickSearchAction.dispose(); showQuickSearchAction = null; collapseAllAction.dispose(); collapseAllAction = null; for ( BrowserViewActionProxy action : browserActionMap.values() ) { action.dispose(); } browserActionMap.clear(); browserActionMap = null; actionBars = null; mainWidget = null; } } /** * Enables the action handlers. * * @param actionBars the action bars */ public void enableGlobalActionHandlers( IActionBars actionBars ) { this.actionBars = actionBars; } /** * Fills the tool bar. * * @param toolBarManager the tool bar manager */ public void fillToolBar( IToolBarManager toolBarManager ) { toolBarManager.add( browserActionMap.get( UP_ACTION ) ); toolBarManager.add( new Separator() ); toolBarManager.add( browserActionMap.get( REFRESH_ACTION ) ); toolBarManager.add( new Separator() ); toolBarManager.add( collapseAllAction ); toolBarManager.update( true ); } /** * Fills the local menu. * * @param menuManager the local menu manager */ public void fillMenu( IMenuManager menuManager ) { menuManager.add( openSortDialogAction ); menuManager.add( new Separator() ); menuManager.add( showQuickSearchAction ); menuManager.add( new Separator() ); menuManager.update( true ); } /** * Fills the context menu. * * @param menuManager the context menu manager */ public void fillContextMenu( IMenuManager menuManager ) { menuManager.setRemoveAllWhenShown( true ); menuManager.addMenuListener( this ); } /** * {@inheritDoc} * * This implementation fills the context menu. */ public void menuAboutToShow( IMenuManager menuManager ) { // up menuManager.add( browserActionMap.get( UP_ACTION ) ); menuManager.add( new Separator() ); // filter menuManager.add( browserActionMap.get( FILTER_CHILDREN_ACTION ) ); if ( ( browserActionMap.get( UNFILTER_CHILDREN_ACTION ) ).isEnabled() ) { menuManager.add( browserActionMap.get( UNFILTER_CHILDREN_ACTION ) ); } menuManager.add( browserActionMap.get( OPEN_QUICK_SEARCH_ACTION ) ); menuManager.add( new Separator() ); // refresh menuManager.add( browserActionMap.get( REFRESH_ACTION ) ); menuManager.add( new Separator() ); // additions menuManager.add( new Separator( IWorkbenchActionConstants.MB_ADDITIONS ) ); menuManager.add( new Separator() ); // properties menuManager.add( browserActionMap.get( PROPERTY_DIALOG_ACTION ) ); } /** * Activates the action handlers. */ public void activateGlobalActionHandlers() { if ( actionBars != null ) { actionBars.setGlobalActionHandler( ActionFactory.REFRESH.getId(), ( IAction ) browserActionMap .get( REFRESH_ACTION ) ); actionBars.setGlobalActionHandler( ActionFactory.PROPERTIES.getId(), ( IAction ) browserActionMap .get( PROPERTY_DIALOG_ACTION ) ); actionBars.setGlobalActionHandler( ActionFactory.FIND.getId(), showQuickSearchAction ); // IWorkbenchActionDefinitionIds.FIND_REPLACE actionBars.updateActionBars(); } else { IAction pda = browserActionMap.get( PROPERTY_DIALOG_ACTION ); pda.setActionDefinitionId( BrowserCommonConstants.CMD_PROPERTIES ); ActionUtils.activateActionHandler( pda ); IAction ra = browserActionMap.get( REFRESH_ACTION ); ActionUtils.activateActionHandler( ra ); showQuickSearchAction.setActionDefinitionId( BrowserCommonConstants.CMD_FIND ); ActionUtils.activateActionHandler( showQuickSearchAction ); } IAction ua = browserActionMap.get( UP_ACTION ); ActionUtils.activateActionHandler( ua ); } /** * Deactivates the action handlers. */ public void deactivateGlobalActionHandlers() { if ( actionBars != null ) { actionBars.setGlobalActionHandler( ActionFactory.REFRESH.getId(), null ); actionBars.setGlobalActionHandler( ActionFactory.PROPERTIES.getId(), null ); actionBars.updateActionBars(); } else { IAction ra = browserActionMap.get( REFRESH_ACTION ); ActionUtils.deactivateActionHandler( ra ); IAction pda = browserActionMap.get( PROPERTY_DIALOG_ACTION ); ActionUtils.deactivateActionHandler( pda ); } IAction ua = browserActionMap.get( UP_ACTION ); ActionUtils.deactivateActionHandler( ua ); } /** * Sets the connection input to all actions * * @param connection the connection */ public void setInput( IBrowserConnection connection ) { for ( BrowserViewActionProxy action : browserActionMap.values() ) { action.inputChanged( connection ); } } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/browser/BrowserSorter.java
plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/browser/BrowserSorter.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.ldapbrowser.common.widgets.browser; import java.math.BigInteger; import org.apache.directory.api.ldap.model.name.Rdn; import org.apache.directory.studio.connection.core.jobs.StudioConnectionRunnableWithProgress; import org.apache.directory.studio.ldapbrowser.core.BrowserCoreConstants; import org.apache.directory.studio.ldapbrowser.core.model.IBookmark; import org.apache.directory.studio.ldapbrowser.core.model.IEntry; import org.apache.directory.studio.ldapbrowser.core.model.IQuickSearch; import org.apache.directory.studio.ldapbrowser.core.model.ISearch; import org.apache.directory.studio.ldapbrowser.core.model.ISearchResult; import org.apache.directory.studio.ldapbrowser.core.model.impl.DirectoryMetadataEntry; import org.apache.directory.studio.ldapbrowser.core.model.impl.RootDSE; import org.eclipse.jface.viewers.TreeViewer; import org.eclipse.jface.viewers.Viewer; import org.eclipse.jface.viewers.ViewerSorter; /** * The BrowserSorter implements the sorter for the browser widget. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class BrowserSorter extends ViewerSorter { /** The browser preferences, used to get the sort settings */ private BrowserPreferences preferences; /** * Creates a new instance of BrowserSorter. * * @param preferences the browser preferences, used to get the sort settings */ public BrowserSorter( BrowserPreferences preferences ) { this.preferences = preferences; } /** * Connects the tree viewer to this sorter. * * @param viewer the tree viewer */ public void connect( TreeViewer viewer ) { viewer.setSorter( this ); } /** * {@inheritDoc} * * For performance reasons this implementation first checks if sorting is enabled * and if the number of elements is less than the sort limit. */ public void sort( final Viewer viewer, final Object[] elements ) { if ( elements != null && ( preferences.getSortLimit() <= 0 || elements.length < preferences.getSortLimit() ) ) { BrowserSorter.super.sort( viewer, elements ); } } /** * {@inheritDoc} * * This method is used to categorize leaf entries, meta entries and normal entries. */ public int category( Object element ) { if ( element instanceof IEntry ) { IEntry entry = ( IEntry ) element; if ( ( entry instanceof DirectoryMetadataEntry || entry instanceof RootDSE || entry.isAlias() || entry .isReferral() ) && preferences.isMetaEntriesLast() ) { return 3; } else if ( entry.isSubentry() ) { return 0; } else if ( !entry.hasChildren() && preferences.isLeafEntriesFirst() ) { return 1; } else if ( entry.hasChildren() && preferences.isContainerEntriesFirst() ) { return 1; } else { return 2; } } else { return 4; } } /** * {@inheritDoc} * * This implementation compares IEntry or ISearchResult objects. Depending on * the sort settings it delegates comparation to {@link #compareRdns(IEntry, IEntry)} * or {@link #compareRdnValues(IEntry, IEntry)}. */ public int compare( Viewer viewer, Object o1, Object o2 ) { // o1 is StudioConnectionRunnableWithProgress if ( o1 instanceof StudioConnectionRunnableWithProgress ) { StudioConnectionRunnableWithProgress runnable = ( StudioConnectionRunnableWithProgress ) o1; for ( Object lockedObject : runnable.getLockedObjects() ) { if ( lockedObject instanceof ISearch ) { ISearch search = ( ISearch ) lockedObject; if ( o1 == search.getTopSearchRunnable() ) { return lessThanEntries(); } else if ( o1 == search.getNextSearchRunnable() ) { return greaterThanEntries(); } } else if ( lockedObject instanceof IEntry ) { IEntry entry = ( IEntry ) lockedObject; if ( o1 == entry.getTopPageChildrenRunnable() ) { return lessThanEntries(); } else if ( o1 == entry.getNextPageChildrenRunnable() ) { return greaterThanEntries(); } } } return lessThanEntries(); } // o2 is StudioConnectionRunnableWithProgress if ( o2 instanceof StudioConnectionRunnableWithProgress ) { StudioConnectionRunnableWithProgress runnable = ( StudioConnectionRunnableWithProgress ) o2; for ( Object lockedObject : runnable.getLockedObjects() ) { if ( lockedObject instanceof ISearch ) { ISearch search = ( ISearch ) lockedObject; if ( o2 == search.getTopSearchRunnable() ) { return greaterThanEntries(); } else if ( o2 == search.getNextSearchRunnable() ) { return lessThanEntries(); } } else if ( lockedObject instanceof IEntry ) { IEntry entry = ( IEntry ) lockedObject; if ( o2 == entry.getTopPageChildrenRunnable() ) { return greaterThanEntries(); } else if ( o2 == entry.getNextPageChildrenRunnable() ) { return lessThanEntries(); } } } return greaterThanEntries(); } // o1 and o2 are null if ( o1 == null && o2 == null ) { return equal(); } // o1 is null, o2 isn't else if ( o1 == null && o2 != null ) { return lessThanEntries(); } // o1 isn't null, o1 is else if ( o1 != null && o2 == null ) { return greaterThanEntries(); } // special case for quick search else if ( o1 instanceof IQuickSearch || o2 instanceof IQuickSearch ) { if ( !( o1 instanceof IQuickSearch ) && ( o2 instanceof IQuickSearch ) ) { return 1; } else if ( ( o1 instanceof IQuickSearch ) && !( o2 instanceof IQuickSearch ) ) { return -1; } else { return equal(); } } // o1 and o2 are entries else if ( o1 instanceof IEntry || o2 instanceof IEntry ) { if ( !( o1 instanceof IEntry ) && !( o2 instanceof IEntry ) ) { return equal(); } else if ( !( o1 instanceof IEntry ) && ( o2 instanceof IEntry ) ) { return lessThanEntries(); } else if ( ( o1 instanceof IEntry ) && !( o2 instanceof IEntry ) ) { return greaterThanEntries(); } else { IEntry entry1 = ( IEntry ) o1; IEntry entry2 = ( IEntry ) o2; int cat1 = category( entry1 ); int cat2 = category( entry2 ); if ( cat1 != cat2 ) { return cat1 - cat2; } else if ( preferences.getSortEntriesBy() == BrowserCoreConstants.SORT_BY_NONE ) { return equal(); } else if ( preferences.getSortEntriesBy() == BrowserCoreConstants.SORT_BY_RDN ) { return compareRdns( entry1, entry2 ); } else if ( preferences.getSortEntriesBy() == BrowserCoreConstants.SORT_BY_RDN_VALUE ) { return compareRdnValues( entry1, entry2 ); } else { return equal(); } } } // o1 and o2 are search results else if ( o1 instanceof ISearchResult || o2 instanceof ISearchResult ) { if ( !( o1 instanceof ISearchResult ) && !( o2 instanceof ISearchResult ) ) { return equal(); } else if ( !( o1 instanceof ISearchResult ) && ( o2 instanceof ISearchResult ) ) { return lessThanEntries(); } else if ( ( o1 instanceof ISearchResult ) && !( o2 instanceof ISearchResult ) ) { return greaterThanEntries(); } else { ISearchResult sr1 = ( ISearchResult ) o1; ISearchResult sr2 = ( ISearchResult ) o2; int cat1 = category( sr1 ); int cat2 = category( sr2 ); if ( cat1 != cat2 ) { return cat1 - cat2; } else if ( preferences.getSortEntriesBy() == BrowserCoreConstants.SORT_BY_NONE ) { return equal(); } else if ( preferences.getSortEntriesBy() == BrowserCoreConstants.SORT_BY_RDN ) { return compareRdns( sr1.getEntry(), sr2.getEntry() ); } else if ( preferences.getSortEntriesBy() == BrowserCoreConstants.SORT_BY_RDN_VALUE ) { return compareRdnValues( sr1.getEntry(), sr2.getEntry() ); } else { return equal(); } } } // o1 and o2 are searches else if ( o1 instanceof ISearch || o2 instanceof ISearch ) { if ( !( o1 instanceof ISearch ) && !( o2 instanceof ISearch ) ) { return equal(); } else if ( !( o1 instanceof ISearch ) && ( o2 instanceof ISearch ) ) { return lessThanSearches(); } else if ( ( o1 instanceof ISearch ) && !( o2 instanceof ISearch ) ) { return greaterThanSearches(); } else { ISearch s1 = ( ISearch ) o1; ISearch s2 = ( ISearch ) o2; if ( preferences.getSortSearchesOrder() == BrowserCoreConstants.SORT_ORDER_NONE ) { return equal(); } else { return compareSearches( s1.getName(), s2.getName() ); } } } // o1 and o2 are bookmarks else if ( o1 instanceof IBookmark || o2 instanceof IBookmark ) { if ( !( o1 instanceof IBookmark ) && !( o2 instanceof IBookmark ) ) { return equal(); } else if ( !( o1 instanceof IBookmark ) && ( o2 instanceof IBookmark ) ) { return lessThanBookmarks(); } else if ( ( o1 instanceof IBookmark ) && !( o2 instanceof IBookmark ) ) { return greaterThanBookmarks(); } else { IBookmark b1 = ( IBookmark ) o1; IBookmark b2 = ( IBookmark ) o2; if ( preferences.getSortBookmarksOrder() == BrowserCoreConstants.SORT_ORDER_NONE ) { return equal(); } else { return compareBookmarks( b1.getName(), b2.getName() ); } } } else { return equal(); } } /** * Compares the string representation of the RDNs of two IEntry objects. * * @param entry1 the first entry * @param entry2 the second entry * @return a negative integer, zero, or a positive integer */ private int compareRdns( IEntry entry1, IEntry entry2 ) { Rdn rdn1 = entry1.getRdn(); Rdn rdn2 = entry2.getRdn(); if ( rdn1 == null && rdn2 == null ) { return equal(); } else if ( rdn1 == null && rdn2 != null ) { return greaterThanEntries(); } else if ( rdn1 != null && rdn2 == null ) { return lessThanEntries(); } else { return compareEntries( rdn1.getName(), rdn2.getName() ); } } /** * Compares the Rdn values of two IEntry objects. * Numeric values are compared as numeric. * * @param entry1 the first entry * @param entry2 the second entry * @return a negative integer, zero, or a positive integer */ private int compareRdnValues( IEntry entry1, IEntry entry2 ) { if ( ( entry1 == null ) && ( entry2 == null ) ) { return equal(); } else if ( ( entry1 != null ) && ( entry2 == null ) ) { return greaterThanEntries(); } else if ( ( entry1 == null ) && ( entry2 != null ) ) { return lessThanEntries(); } else { Rdn rdn1 = entry1.getRdn(); Rdn rdn2 = entry2.getRdn(); if ( ( rdn1 == null || rdn1.getName() == null || "".equals( rdn1.getName() ) ) //$NON-NLS-1$ && ( rdn2 == null || rdn2.getName() == null || "".equals( rdn2.getName() ) ) ) //$NON-NLS-1$ { return equal(); } else if ( ( rdn1 == null || rdn1.getName() == null || "".equals( rdn1.getName() ) ) //$NON-NLS-1$ && !( rdn2 == null || rdn2.getName() == null || "".equals( rdn2.getName() ) ) ) //$NON-NLS-1$ { return greaterThanEntries(); } else if ( !( rdn1 == null || rdn1.getName() == null || "".equals( rdn1.getName() ) ) //$NON-NLS-1$ && ( rdn2 == null || rdn2.getName() == null || "".equals( rdn2.getName() ) ) ) //$NON-NLS-1$ { return lessThanEntries(); } String rdn1Value = ( String ) rdn1.getName(); String rdn2Value = ( String ) rdn2.getName(); if ( rdn1Value.matches( "\\d*" ) && !rdn2Value.matches( "\\d*" ) ) //$NON-NLS-1$ //$NON-NLS-2$ { // return lessThan(); return compareEntries( rdn1Value, rdn2Value ); } else if ( !rdn1Value.matches( "\\d*" ) && rdn2Value.matches( "\\d*" ) ) //$NON-NLS-1$ //$NON-NLS-2$ { // return greaterThan(); return compareEntries( rdn1Value, rdn2Value ); } else if ( rdn2Value.matches( "\\d*" ) && rdn2Value.matches( "\\d*" ) ) //$NON-NLS-1$ //$NON-NLS-2$ { BigInteger bi1 = new BigInteger( rdn1Value ); BigInteger bi2 = new BigInteger( rdn2Value ); return compare( bi1, bi2 ); // return Integer.parseInt(rdn1.getValue()) - // Integer.parseInt(rdn2.getValue()); } else { return compareEntries( rdn1Value, rdn2Value ); } } } /** * Returns +1 or -1, depending on the sort entries order. * * @return +1 or -1, depending on the sort entries order */ private int lessThanEntries() { return preferences.getSortEntriesOrder() == BrowserCoreConstants.SORT_ORDER_ASCENDING ? -1 : 1; } /** * Returns +1 or -1, depending on the sort searches order. * * @return +1 or -1, depending on the sort searches order */ private int lessThanSearches() { return preferences.getSortSearchesOrder() == BrowserCoreConstants.SORT_ORDER_ASCENDING ? -1 : 1; } /** * Returns +1 or -1, depending on the sort entries order. * * @return +1 or -1, depending on the sort entries order */ private int lessThanBookmarks() { return preferences.getSortBookmarksOrder() == BrowserCoreConstants.SORT_ORDER_ASCENDING ? -1 : 1; } /** * Returns 0. * * @return 0 */ private int equal() { return 0; } /** * Returns +1 or -1, depending on the sort entries order. * * @return +1 or -1, depending on the sort entries order */ private int greaterThanEntries() { return preferences.getSortEntriesOrder() == BrowserCoreConstants.SORT_ORDER_ASCENDING ? 1 : -1; } /** * Returns +1 or -1, depending on the sort searches order. * * @return +1 or -1, depending on the sort searches order */ private int greaterThanSearches() { return preferences.getSortSearchesOrder() == BrowserCoreConstants.SORT_ORDER_ASCENDING ? 1 : -1; } /** * Returns +1 or -1, depending on the sort bookmarks order. * * @return +1 or -1, depending on the sort bookmarks order */ private int greaterThanBookmarks() { return preferences.getSortBookmarksOrder() == BrowserCoreConstants.SORT_ORDER_ASCENDING ? 1 : -1; } /** * Compares the two strings using the Strings's compareToIgnoreCase method, * pays attention for the sort entries order. * * @param s1 the first string to compare * @param s2 the second string to compare * @return a negative integer, zero, or a positive integer * @see java.lang.String#compareToIgnoreCase(String) */ private int compareEntries( String s1, String s2 ) { return preferences.getSortEntriesOrder() == BrowserCoreConstants.SORT_ORDER_ASCENDING ? s1 .compareToIgnoreCase( s2 ) : s2.compareToIgnoreCase( s1 ); } /** * Compares the two strings using the Strings's compareToIgnoreCase method, * pays attention for the sort searches order. * * @param s1 the first string to compare * @param s2 the second string to compare * @return a negative integer, zero, or a positive integer * @see java.lang.String#compareToIgnoreCase(String) */ private int compareSearches( String s1, String s2 ) { return preferences.getSortSearchesOrder() == BrowserCoreConstants.SORT_ORDER_ASCENDING ? s1 .compareToIgnoreCase( s2 ) : s2.compareToIgnoreCase( s1 ); } /** * Compares the two strings using the Strings's compareToIgnoreCase method, * pays attention for the sort bookmarks order. * * @param s1 the first string to compare * @param s2 the second string to compare * @return a negative integer, zero, or a positive integer * @see java.lang.String#compareToIgnoreCase(String) */ private int compareBookmarks( String s1, String s2 ) { return preferences.getSortBookmarksOrder() == BrowserCoreConstants.SORT_ORDER_ASCENDING ? s1 .compareToIgnoreCase( s2 ) : s2.compareToIgnoreCase( s1 ); } /** * Compares the two numbers using the BigInteger compareTo method, * pays attention for the sort order. * * @param bi1 the first number to compare * @param bi1 the second number to compare * @return -1, 0 or 1 as this BigInteger is numerically less than, equal * to, or greater than * @see java.math.BigInteger#compareTo(BigInteger) */ private int compare( BigInteger bi1, BigInteger bi2 ) { return preferences.getSortEntriesOrder() == BrowserCoreConstants.SORT_ORDER_ASCENDING ? bi1.compareTo( bi2 ) : bi2.compareTo( bi1 ); } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/browser/BrowserCategory.java
plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/browser/BrowserCategory.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.ldapbrowser.common.widgets.browser; import org.apache.directory.studio.ldapbrowser.core.model.IBrowserConnection; import org.eclipse.core.runtime.IAdaptable; /** * A BrowserCategory is the top-level node in the browser widget. * There are three types: DIT categories, searches categories * and bookmarks categories. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class BrowserCategory implements IAdaptable { /** The Constant TYPE_DIT identifies DIT categories. */ public static final int TYPE_DIT = 0; /** The Constant TYPE_SEARCHES identifies searches categories. */ public static final int TYPE_SEARCHES = 1; /** The Constant TYPE_BOOKMARKS identifies bookmark categories. */ public static final int TYPE_BOOKMARKS = 2; /** The title for the DIT categoy */ public static final String TITLE_DIT = Messages.getString( "BrowserCategory.DIT" ); //$NON-NLS-1$ /** The title for the searches categoy */ public static final String TITLE_SEARCHES = Messages.getString( "BrowserCategory.Searches" ); //$NON-NLS-1$ /** The title for the bookmarks categoy */ public static final String TITLE_BOOKMARKS = Messages.getString( "BrowserCategory.Bookmarks" ); //$NON-NLS-1$ /** The category's connection */ private IBrowserConnection parent; /** The category's type */ private int type; /** * Creates a new instance of BrowserCategory. * * @param type the category's type, one of TYPE_DIT, TYPE_SEARCHES or TYPE_BOOKMARKS * @param parent the category's connection */ public BrowserCategory( int type, IBrowserConnection parent ) { this.parent = parent; this.type = type; } /** * Gets the category's parent, which is always a connection. * * @return the parent connection */ public IBrowserConnection getParent() { return parent; } /** * Gets the category's type, one of TYPE_DIT, TYPE_SEARCHES or TYPE_BOOKMARKS. * * @return the category's type. */ public int getType() { return type; } /** * Gets the category's title. * * @return the category's title */ public String getTitle() { switch ( type ) { case TYPE_DIT: return TITLE_DIT; case TYPE_SEARCHES: return TITLE_SEARCHES; case TYPE_BOOKMARKS: return TITLE_BOOKMARKS; default: return "ERROR"; //$NON-NLS-1$ } } /** * {@inheritDoc} */ public Object getAdapter( Class adapter ) { 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/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/dialogs/DeleteDialog.java
plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/dialogs/DeleteDialog.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.ldapbrowser.common.dialogs; import org.apache.directory.studio.ldapbrowser.common.BrowserCommonActivator; import org.eclipse.jface.dialogs.IDialogConstants; import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.swt.SWT; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Shell; /** * Dialog that prompts a user to delete items in the browser tree. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class DeleteDialog extends MessageDialog { /** The "Use Tree Delete Control" dialog setting . */ private static final String USE_TREE_DELETE_CONTROL_DIALOGSETTING_KEY = DeleteDialog.class.getName() + ".useTreeDeleteControl"; //$NON-NLS-1$ private Button useTreeDeleteControlCheckbox; private boolean askForTreeDeleteControl; private boolean useTreeDeleteControl; /** * Instantiates a new delete dialog. * * @param parentShell the parent shell * @param title the title * @param message the message * @param askForTreeDeleteControl true if the user should be asked if the tree delete control should be used */ public DeleteDialog( Shell parentShell, String title, String message, boolean askForTreeDeleteControl ) { super( parentShell, title, null, message, QUESTION, new String[] { IDialogConstants.OK_LABEL, IDialogConstants.CANCEL_LABEL }, OK ); this.askForTreeDeleteControl = askForTreeDeleteControl; this.useTreeDeleteControl = false; if ( BrowserCommonActivator.getDefault().getDialogSettings().get( USE_TREE_DELETE_CONTROL_DIALOGSETTING_KEY ) == null ) { BrowserCommonActivator.getDefault().getDialogSettings().put( USE_TREE_DELETE_CONTROL_DIALOGSETTING_KEY, false ); } } @Override protected Control createCustomArea( Composite parent ) { if ( askForTreeDeleteControl ) { useTreeDeleteControlCheckbox = new Button( parent, SWT.CHECK ); useTreeDeleteControlCheckbox.setText( Messages.getString( "DeleteDialog.UseTreeDeleteControl" ) ); //$NON-NLS-1$ useTreeDeleteControlCheckbox.setSelection( BrowserCommonActivator.getDefault().getDialogSettings() .getBoolean( USE_TREE_DELETE_CONTROL_DIALOGSETTING_KEY ) ); return useTreeDeleteControlCheckbox; } else { return null; } } @Override protected void buttonPressed( int buttonId ) { if ( buttonId == OK ) { useTreeDeleteControl = useTreeDeleteControlCheckbox != null && useTreeDeleteControlCheckbox.getSelection(); if ( useTreeDeleteControlCheckbox != null ) { BrowserCommonActivator.getDefault().getDialogSettings().put( USE_TREE_DELETE_CONTROL_DIALOGSETTING_KEY, useTreeDeleteControlCheckbox.getSelection() ); } } super.buttonPressed( buttonId ); } /** * Checks if tree delete control should be used. * * @return true, if tree delete control should be used */ public boolean isUseTreeDeleteControl() { return useTreeDeleteControl; } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/dialogs/SelectBrowserConnectionDialog.java
plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/dialogs/SelectBrowserConnectionDialog.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.ldapbrowser.common.dialogs; import org.apache.directory.studio.connection.core.Connection; import org.apache.directory.studio.connection.core.ConnectionCorePlugin; import org.apache.directory.studio.connection.ui.widgets.ConnectionActionGroup; import org.apache.directory.studio.connection.ui.widgets.ConnectionConfiguration; import org.apache.directory.studio.connection.ui.widgets.ConnectionUniversalListener; import org.apache.directory.studio.connection.ui.widgets.ConnectionWidget; import org.apache.directory.studio.ldapbrowser.core.BrowserCorePlugin; 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.DoubleClickEvent; import org.eclipse.jface.viewers.IDoubleClickListener; import org.eclipse.jface.viewers.ISelectionChangedListener; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jface.viewers.SelectionChangedEvent; import org.eclipse.jface.viewers.StructuredSelection; import org.eclipse.swt.SWT; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Shell; /** * Dialog to select an {@link IBrowserConnection}. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class SelectBrowserConnectionDialog extends Dialog { /** The title */ private String title; /** The initial browser connection */ private IBrowserConnection initialBrowserConnection; /** The selected browser connection */ private IBrowserConnection selectedBrowserConnection; /** The connection configuration */ private ConnectionConfiguration connectionConfiguration; /** The connection universal listener */ private ConnectionUniversalListener connectionUniversalListener; /** The connection action group */ private ConnectionActionGroup connectionActionGroup; /** The connection main widget */ private ConnectionWidget connectionMainWidget; /** * Creates a new instance of SelectConnectionDialog. * * @param parentShell the parent shell * @param title the title * @param initialBrowserConnection the initial browser connection */ public SelectBrowserConnectionDialog( Shell parentShell, String title, IBrowserConnection initialBrowserConnection ) { super( parentShell ); super.setShellStyle( super.getShellStyle() | SWT.RESIZE ); this.title = title; this.initialBrowserConnection = initialBrowserConnection; this.selectedBrowserConnection = null; } /** * @see org.eclipse.jface.window.Window#configureShell(org.eclipse.swt.widgets.Shell) */ protected void configureShell( Shell shell ) { super.configureShell( shell ); shell.setText( title ); } /** * @see org.eclipse.jface.dialogs.Dialog#close() */ public boolean close() { if ( connectionMainWidget != null ) { connectionConfiguration.dispose(); connectionConfiguration = null; connectionActionGroup.deactivateGlobalActionHandlers(); connectionActionGroup.dispose(); connectionActionGroup = null; connectionUniversalListener.dispose(); connectionUniversalListener = null; connectionMainWidget.dispose(); connectionMainWidget = null; } return super.close(); } /** * @see org.eclipse.jface.dialogs.Dialog#okPressed() */ protected void okPressed() { selectedBrowserConnection = initialBrowserConnection; super.okPressed(); } /** * @see org.eclipse.jface.dialogs.Dialog#cancelPressed() */ protected void cancelPressed() { selectedBrowserConnection = null; super.cancelPressed(); } /** * @see org.eclipse.jface.dialogs.Dialog#createButtonsForButtonBar(org.eclipse.swt.widgets.Composite) */ protected void createButtonsForButtonBar( Composite parent ) { createButton( parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, false ); createButton( parent, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL, false ); } /** * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite) */ protected Control createDialogArea( Composite parent ) { Composite composite = ( Composite ) super.createDialogArea( parent ); GridLayout gl = new GridLayout(); composite.setLayout( gl ); 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 ); // create configuration connectionConfiguration = new ConnectionConfiguration(); // create main widget connectionMainWidget = new ConnectionWidget( connectionConfiguration, null ); connectionMainWidget.createWidget( composite ); connectionMainWidget.setInput( ConnectionCorePlugin.getDefault().getConnectionFolderManager() ); // create actions and context menu (and register global actions) connectionActionGroup = new ConnectionActionGroup( connectionMainWidget, connectionConfiguration ); connectionActionGroup.fillToolBar( connectionMainWidget.getToolBarManager() ); connectionActionGroup.fillMenu( connectionMainWidget.getMenuManager() ); connectionActionGroup.fillContextMenu( connectionMainWidget.getContextMenuManager() ); connectionActionGroup.activateGlobalActionHandlers(); // create the listener connectionUniversalListener = new ConnectionUniversalListener( connectionMainWidget.getViewer() ); connectionMainWidget.getViewer().addSelectionChangedListener( new ISelectionChangedListener() { public void selectionChanged( SelectionChangedEvent event ) { if ( !event.getSelection().isEmpty() ) { Object o = ( ( IStructuredSelection ) event.getSelection() ).getFirstElement(); if ( o instanceof Connection ) { Connection connection = ( Connection ) o; IBrowserConnection browserConnection = BrowserCorePlugin.getDefault().getConnectionManager() .getBrowserConnection( connection ); initialBrowserConnection = browserConnection; } } } } ); connectionMainWidget.getViewer().addDoubleClickListener( new IDoubleClickListener() { public void doubleClick( DoubleClickEvent event ) { if ( !event.getSelection().isEmpty() ) { Object o = ( ( IStructuredSelection ) event.getSelection() ).getFirstElement(); if ( o instanceof Connection ) { Connection connection = ( Connection ) o; IBrowserConnection browserConnection = BrowserCorePlugin.getDefault().getConnectionManager() .getBrowserConnection( connection ); initialBrowserConnection = browserConnection; okPressed(); } } } } ); if ( initialBrowserConnection != null ) { Connection connection = initialBrowserConnection.getConnection(); if ( connection != null ) { connectionMainWidget.getViewer().reveal( connection ); connectionMainWidget.getViewer().setSelection( new StructuredSelection( connection ), true ); } } applyDialogFont( composite ); connectionMainWidget.setFocus(); return composite; } /** * Gets the selected browser connection or null if the dialog was canceled. * * @return the selected browser connection or null if the dialog was canceled */ public IBrowserConnection getSelectedBrowserConnection() { return selectedBrowserConnection; } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/dialogs/ScopeDialog.java
plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/dialogs/ScopeDialog.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.ldapbrowser.common.dialogs; import org.apache.directory.api.ldap.model.message.SearchScope; import org.apache.directory.studio.common.ui.widgets.BaseWidgetUtils; import org.eclipse.jface.dialogs.Dialog; import org.eclipse.jface.dialogs.IDialogConstants; import org.eclipse.swt.SWT; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Group; import org.eclipse.swt.widgets.Shell; /** * A dialog to select the scope of a copy operation. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class ScopeDialog extends Dialog { /** The dialog title. */ private String dialogTitle; /** The multiple entries selected flag. */ private boolean multipleEntriesSelected; /** The scope. */ private SearchScope scope; /** The object scope button. */ private Button objectScopeButton; /** The onelevel scope button. */ private Button onelevelScopeButton; /** The subtree scope button. */ private Button subtreeScopeButton; /** * Creates a new instance of ScopeDialog. * * @param parentShell the parent shell * @param dialogTitle the dialog title * @param multipleEntriesSelected the multiple entries selected */ public ScopeDialog( Shell parentShell, String dialogTitle, boolean multipleEntriesSelected ) { super( parentShell ); super.setShellStyle( super.getShellStyle() | SWT.RESIZE ); this.dialogTitle = dialogTitle; this.multipleEntriesSelected = multipleEntriesSelected; } /** * @see org.eclipse.jface.window.Window#configureShell(org.eclipse.swt.widgets.Shell) */ protected void configureShell( Shell shell ) { super.configureShell( shell ); shell.setText( dialogTitle ); } /** * @see org.eclipse.jface.dialogs.Dialog#okPressed() */ protected void okPressed() { scope = objectScopeButton.getSelection() ? SearchScope.OBJECT : onelevelScopeButton.getSelection() ? SearchScope.ONELEVEL : SearchScope.SUBTREE; super.okPressed(); } /** * @see org.eclipse.jface.dialogs.Dialog#createButtonsForButtonBar(org.eclipse.swt.widgets.Composite) */ protected void createButtonsForButtonBar( Composite parent ) { createButton( parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, false ); createButton( parent, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL, false ); } /** * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite) */ protected Control createDialogArea( Composite parent ) { Composite composite = ( Composite ) super.createDialogArea( parent ); GridData gd = new GridData( GridData.FILL_BOTH ); composite.setLayoutData( gd ); Group group = BaseWidgetUtils.createGroup( composite, Messages.getString( "ScopeDialog.SelectCopyDepth" ), 1 ); //$NON-NLS-1$ objectScopeButton = new Button( group, SWT.RADIO ); objectScopeButton.setSelection( true ); objectScopeButton.setText( multipleEntriesSelected ? Messages.getString( "ScopeDialog.OnlyCopiedEntries" ) //$NON-NLS-1$ : Messages.getString( "ScopeDialog.OnlyCopiedEntry" ) ); //$NON-NLS-1$ onelevelScopeButton = new Button( group, SWT.RADIO ); onelevelScopeButton.setText( multipleEntriesSelected ? Messages .getString( "ScopeDialog.CopiedEntriesAndDirectChildren" ) //$NON-NLS-1$ : Messages.getString( "ScopeDialog.CopiedEntryAndDirectChildren" ) ); //$NON-NLS-1$ subtreeScopeButton = new Button( group, SWT.RADIO ); subtreeScopeButton.setText( multipleEntriesSelected ? Messages.getString( "ScopeDialog.WholeSubtrees" ) //$NON-NLS-1$ : Messages.getString( "ScopeDialog.WholeSubtree" ) ); //$NON-NLS-1$ applyDialogFont( composite ); return composite; } /** * Gets the scope. * * @return the scope */ public SearchScope getScope() { return scope; } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/dialogs/SelectEntryDialog.java
plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/dialogs/SelectEntryDialog.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.ldapbrowser.common.dialogs; import org.apache.directory.studio.ldapbrowser.common.widgets.browser.BrowserActionGroup; import org.apache.directory.studio.ldapbrowser.common.widgets.browser.BrowserConfiguration; import org.apache.directory.studio.ldapbrowser.common.widgets.browser.BrowserUniversalListener; import org.apache.directory.studio.ldapbrowser.common.widgets.browser.BrowserWidget; import org.apache.directory.studio.ldapbrowser.core.model.IEntry; import org.apache.directory.studio.ldapbrowser.core.model.ISearchResult; import org.eclipse.jface.dialogs.Dialog; import org.eclipse.jface.dialogs.IDialogConstants; import org.eclipse.jface.viewers.ISelectionChangedListener; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jface.viewers.SelectionChangedEvent; import org.eclipse.jface.viewers.StructuredSelection; import org.eclipse.swt.SWT; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Shell; /** * Dialog to select an entry. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class SelectEntryDialog extends Dialog { /** The dialog title. */ private String title; /** The root entry. */ private IEntry rootEntry; /** The initial entry. */ private IEntry initialEntry; /** The selected entry. */ private IEntry selectedEntry; /** The browser configuration. */ private BrowserConfiguration browserConfiguration; /** The browser universal listener. */ private BrowserUniversalListener browserUniversalListener; /** The browser action group. */ private BrowserActionGroup browserActionGroup; /** The browser widget. */ private BrowserWidget browserWidget; /** * Creates a new instance of SelectEntryDialog. * * @param parentShell the parent shell * @param title the title * @param rootEntry the root entry * @param initialEntry the initial entry */ public SelectEntryDialog( Shell parentShell, String title, IEntry rootEntry, IEntry initialEntry ) { super( parentShell ); super.setShellStyle( super.getShellStyle() | SWT.RESIZE ); this.title = title; this.rootEntry = rootEntry; this.initialEntry = initialEntry; this.selectedEntry = null; } /** * @see org.eclipse.jface.window.Window#configureShell(org.eclipse.swt.widgets.Shell) */ protected void configureShell( Shell shell ) { super.configureShell( shell ); shell.setText( title ); } /** * @see org.eclipse.jface.dialogs.Dialog#close() */ public boolean close() { if ( browserWidget != null ) { browserConfiguration.dispose(); browserConfiguration = null; browserActionGroup.deactivateGlobalActionHandlers(); browserActionGroup.dispose(); browserActionGroup = null; browserUniversalListener.dispose(); browserUniversalListener = null; browserWidget.dispose(); browserWidget = null; } return super.close(); } /** * @see org.eclipse.jface.dialogs.Dialog#okPressed() */ protected void okPressed() { selectedEntry = initialEntry; super.okPressed(); } /** * @see org.eclipse.jface.dialogs.Dialog#cancelPressed() */ protected void cancelPressed() { selectedEntry = null; super.cancelPressed(); } /** * @see org.eclipse.jface.dialogs.Dialog#createButtonsForButtonBar(org.eclipse.swt.widgets.Composite) */ protected void createButtonsForButtonBar( Composite parent ) { createButton( parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, false ); createButton( parent, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL, false ); } /** * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite) */ 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 = convertHorizontalDLUsToPixels( IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH ); composite.setLayoutData( gd ); // create configuration browserConfiguration = new BrowserConfiguration(); // create main widget browserWidget = new BrowserWidget( browserConfiguration, null ); browserWidget.createWidget( composite ); browserWidget.setInput( new IEntry[] { rootEntry } ); // create actions and context menu (and register global actions) browserActionGroup = new BrowserActionGroup( browserWidget, browserConfiguration ); browserActionGroup.fillToolBar( browserWidget.getToolBarManager() ); browserActionGroup.fillMenu( browserWidget.getMenuManager() ); browserActionGroup.fillContextMenu( browserWidget.getContextMenuManager() ); browserActionGroup.activateGlobalActionHandlers(); // create the listener browserUniversalListener = new BrowserUniversalListener( browserWidget ); browserWidget.getViewer().addSelectionChangedListener( new ISelectionChangedListener() { public void selectionChanged( SelectionChangedEvent event ) { if ( !event.getSelection().isEmpty() ) { Object o = ( ( IStructuredSelection ) event.getSelection() ).getFirstElement(); if ( o instanceof IEntry ) { initialEntry = ( IEntry ) o; } else if ( o instanceof ISearchResult ) { initialEntry = ( ( ISearchResult ) o ).getEntry(); } } } } ); browserWidget.getViewer().expandToLevel( 2 ); if ( initialEntry != null ) { IEntry entry = this.initialEntry; browserWidget.getViewer().reveal( entry ); browserWidget.getViewer().refresh( entry, true ); browserWidget.getViewer().setSelection( new StructuredSelection( entry ), true ); browserWidget.getViewer().setSelection( new StructuredSelection( entry ), true ); } applyDialogFont( composite ); browserWidget.setFocus(); return composite; } /** * Gets the selected entry. * * @return the selected entry */ public IEntry getSelectedEntry() { return selectedEntry; } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/dialogs/MultivaluedDialog.java
plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/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.ldapbrowser.common.dialogs; import java.util.Iterator; import org.apache.directory.studio.ldapbrowser.common.BrowserCommonActivator; import org.apache.directory.studio.ldapbrowser.common.BrowserCommonConstants; import org.apache.directory.studio.ldapbrowser.common.widgets.entryeditor.EntryEditorWidget; import org.apache.directory.studio.ldapbrowser.common.widgets.entryeditor.EntryEditorWidgetActionGroup; import org.apache.directory.studio.ldapbrowser.common.widgets.entryeditor.EntryEditorWidgetConfiguration; import org.apache.directory.studio.ldapbrowser.common.widgets.entryeditor.EntryEditorWidgetUniversalListener; import org.apache.directory.studio.ldapbrowser.common.widgets.entryeditor.OpenDefaultEditorAction; import org.apache.directory.studio.ldapbrowser.core.events.AttributeDeletedEvent; import org.apache.directory.studio.ldapbrowser.core.events.EmptyValueAddedEvent; import org.apache.directory.studio.ldapbrowser.core.events.EmptyValueDeletedEvent; import org.apache.directory.studio.ldapbrowser.core.events.EntryModificationEvent; import org.apache.directory.studio.ldapbrowser.core.events.EventRegistry; import org.apache.directory.studio.ldapbrowser.core.events.ValueAddedEvent; import org.apache.directory.studio.ldapbrowser.core.events.ValueDeletedEvent; import org.apache.directory.studio.ldapbrowser.core.events.ValueModifiedEvent; import org.apache.directory.studio.ldapbrowser.core.events.ValueMultiModificationEvent; import org.apache.directory.studio.ldapbrowser.core.model.AttributeHierarchy; import org.apache.directory.studio.ldapbrowser.core.model.IAttribute; import org.apache.directory.studio.ldapbrowser.core.model.IEntry; import org.apache.directory.studio.ldapbrowser.core.model.IValue; import org.apache.directory.studio.ldapbrowser.core.utils.CompoundModification; import org.apache.directory.studio.ldapbrowser.core.utils.Utils; import org.apache.directory.studio.ldifparser.model.LdifFile; import org.apache.directory.studio.valueeditors.ValueEditorManager; import org.eclipse.jface.dialogs.Dialog; import org.eclipse.jface.viewers.StructuredSelection; import org.eclipse.jface.viewers.TreeViewer; import org.eclipse.swt.SWT; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Shell; import org.eclipse.ui.PlatformUI; import org.eclipse.ui.contexts.IContextActivation; import org.eclipse.ui.contexts.IContextService; /** * Dialog to view and edit multi-valued attributes. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class MultivaluedDialog extends Dialog { /** The dialog title. */ private static final String DIALOG_TITLE = Messages.getString( "MultivaluedDialog.MultivaluedEditor" ); //$NON-NLS-1$ /** The attribute hierarchy to edit. */ private AttributeHierarchy workingAttributeHierarchy; /** The original attribute hierarchy. */ private AttributeHierarchy referenceAttributeHierarchy; /** The entry editor widget configuration. */ private MultiValuedEntryEditorConfiguration configuration; /** The entry edtior widget action group. */ private EntryEditorWidgetActionGroup actionGroup; /** The entry editor widget. */ private EntryEditorWidget mainWidget; /** The universal listener. */ private MultiValuedEntryEditorUniversalListener universalListener; /** Token used to activate and deactivate shortcuts in the editor */ private IContextActivation contextActivation; /** * Creates a new instance of MultivaluedDialog. * * @param parentShell the parent shell * @param workingAttributeHierarchy the attribute hierarchy */ public MultivaluedDialog( Shell parentShell, AttributeHierarchy attributeHierarchy ) { super( parentShell ); setShellStyle( getShellStyle() | SWT.RESIZE ); this.referenceAttributeHierarchy = attributeHierarchy; // clone the entry and attribute hierarchy IEntry entry = attributeHierarchy.getEntry(); String attributeDescription = attributeHierarchy.getAttributeDescription(); IEntry clone = new CompoundModification().cloneEntry( entry ); this.workingAttributeHierarchy = clone.getAttributeWithSubtypes( attributeDescription ); } /** * @see org.eclipse.jface.window.Window#configureShell(org.eclipse.swt.widgets.Shell) */ protected void configureShell( Shell shell ) { super.configureShell( shell ); shell.setText( DIALOG_TITLE ); shell.setImage( BrowserCommonActivator.getDefault().getImage( BrowserCommonConstants.IMG_MULTIVALUEDEDITOR ) ); } @Override protected void okPressed() { LdifFile diff = Utils .computeDiff( referenceAttributeHierarchy.getEntry(), workingAttributeHierarchy.getEntry() ); if ( diff != null ) { EventRegistry.suspendEventFiringInCurrentThread(); IEntry entry = referenceAttributeHierarchy.getEntry(); for ( IAttribute attribute : referenceAttributeHierarchy.getAttributes() ) { entry.deleteAttribute( attribute ); } for ( IAttribute attribute : workingAttributeHierarchy.getAttributes() ) { entry.addAttribute( attribute ); } EventRegistry.resumeEventFiringInCurrentThread(); ValueMultiModificationEvent event = new ValueMultiModificationEvent( entry.getBrowserConnection(), entry ); EventRegistry.fireEntryUpdated( event, this ); } super.okPressed(); } /** * @see org.eclipse.jface.window.Window#open() */ public int open() { if ( workingAttributeHierarchy.getAttribute().getValueSize() == 0 ) { workingAttributeHierarchy.getAttribute().addEmptyValue(); } return super.open(); } /** * @see org.eclipse.jface.dialogs.Dialog#close() */ public boolean close() { boolean returnValue = super.close(); if ( returnValue ) { dispose(); // cleanup attribute hierarchy after editing for ( Iterator<IAttribute> it = workingAttributeHierarchy.iterator(); it.hasNext(); ) { IAttribute attribute = it.next(); if ( attribute != null ) { // remove empty values IValue[] values = attribute.getValues(); for ( int i = 0; i < values.length; i++ ) { if ( values[i].isEmpty() ) { attribute.deleteEmptyValue(); } } // delete attribute from entry if all values were deleted if ( attribute.getValueSize() == 0 ) { attribute.getEntry().deleteAttribute( attribute ); } } } } return returnValue; } /** * Disposes all widgets. */ public void dispose() { if ( configuration != null ) { universalListener.dispose(); universalListener = null; mainWidget.dispose(); mainWidget = null; actionGroup.deactivateGlobalActionHandlers(); actionGroup.dispose(); actionGroup = null; configuration.dispose(); configuration = null; if ( contextActivation != null ) { IContextService contextService = ( IContextService ) PlatformUI.getWorkbench().getAdapter( IContextService.class ); contextService.deactivateContext( contextActivation ); contextActivation = null; } } } /** * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite) */ protected Control createDialogArea( Composite parent ) { Composite composite = ( Composite ) super.createDialogArea( parent ); // create configuration configuration = new MultiValuedEntryEditorConfiguration(); // create main widget mainWidget = new EntryEditorWidget( configuration ); mainWidget.createWidget( composite ); mainWidget.getViewer().getTree().setFocus(); // create actions actionGroup = new EntryEditorWidgetActionGroup( mainWidget, configuration ); actionGroup.fillToolBar( mainWidget.getToolBarManager() ); actionGroup.fillMenu( mainWidget.getMenuManager() ); actionGroup.fillContextMenu( mainWidget.getContextMenuManager() ); IContextService contextService = ( IContextService ) PlatformUI.getWorkbench().getAdapter( IContextService.class ); contextActivation = contextService.activateContext( BrowserCommonConstants.CONTEXT_DIALOGS ); actionGroup.activateGlobalActionHandlers(); // create the listener universalListener = new MultiValuedEntryEditorUniversalListener( mainWidget.getViewer(), configuration, actionGroup, actionGroup.getOpenDefaultEditorAction() ); universalListener.setInput( workingAttributeHierarchy ); // start edit mode if an empty value exists for ( Iterator<IAttribute> it = workingAttributeHierarchy.iterator(); it.hasNext(); ) { IAttribute attribute = it.next(); IValue[] values = attribute.getValues(); for ( int i = 0; i < values.length; i++ ) { IValue value = values[i]; if ( value.isEmpty() ) { mainWidget.getViewer().setSelection( new StructuredSelection( value ), true ); if ( actionGroup.getOpenDefaultEditorAction().isEnabled() ) { actionGroup.getOpenDefaultEditorAction().run(); break; } } } } applyDialogFont( composite ); return composite; } /** * A special listener for the {@link MultivaluedDialog}. */ class MultiValuedEntryEditorUniversalListener extends EntryEditorWidgetUniversalListener { /** * Creates a new instance of MultiValuedEntryEditorUniversalListener. * * @param treeViewer the tree viewer * @param configuration the configuration * @param actionGroup the action group * @param startEditAction the start edit action */ public MultiValuedEntryEditorUniversalListener( TreeViewer treeViewer, EntryEditorWidgetConfiguration configuration, EntryEditorWidgetActionGroup actionGroup, OpenDefaultEditorAction startEditAction ) { super( treeViewer, configuration, actionGroup, startEditAction ); } /** * @see org.apache.directory.studio.ldapbrowser.common.widgets.entryeditor.EntryEditorWidgetUniversalListener#entryUpdated(org.apache.directory.studio.ldapbrowser.core.events.EntryModificationEvent) */ public void entryUpdated( EntryModificationEvent event ) { if ( viewer == null || viewer.getTree() == null || viewer.getTree().isDisposed() ) { return; } if ( viewer.isCellEditorActive() ) { viewer.cancelEditing(); } viewer.refresh(); // select added/modified value if ( event instanceof ValueAddedEvent ) { ValueAddedEvent vaEvent = ( ValueAddedEvent ) event; viewer.setSelection( new StructuredSelection( vaEvent.getAddedValue() ), true ); viewer.refresh(); } else if ( event instanceof ValueModifiedEvent ) { ValueModifiedEvent vmEvent = ( ValueModifiedEvent ) event; viewer.setSelection( new StructuredSelection( vmEvent.getNewValue() ), true ); } else if ( event instanceof ValueDeletedEvent ) { ValueDeletedEvent vdEvent = ( ValueDeletedEvent ) event; if ( vdEvent.getDeletedValue().getAttribute().getValueSize() > 0 ) { viewer.setSelection( new StructuredSelection( vdEvent.getDeletedValue().getAttribute().getValues()[0] ), true ); } } else if ( event instanceof EmptyValueAddedEvent ) { viewer.refresh(); EmptyValueAddedEvent evaEvent = ( EmptyValueAddedEvent ) event; viewer.setSelection( new StructuredSelection( evaEvent.getAddedValue() ), true ); if ( startEditAction.isEnabled() ) startEditAction.run(); } else if ( event instanceof EmptyValueDeletedEvent ) { EmptyValueDeletedEvent evdEvent = ( EmptyValueDeletedEvent ) event; if ( viewer.getSelection().isEmpty() && evdEvent.getDeletedValue().getAttribute().getValueSize() > 0 ) viewer.setSelection( new StructuredSelection( evdEvent.getDeletedValue().getAttribute().getValues()[0] ), true ); } else if ( event instanceof AttributeDeletedEvent ) { } } } /** * A special configuration for the {@link MultivaluedDialog}. */ class MultiValuedEntryEditorConfiguration extends EntryEditorWidgetConfiguration { @Override public ValueEditorManager getValueEditorManager( TreeViewer viewer ) { if ( valueEditorManager == null ) { valueEditorManager = new ValueEditorManager( viewer.getTree(), false, false ); } return valueEditorManager; } } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/dialogs/FilterWidgetDialog.java
plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/dialogs/FilterWidgetDialog.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.ldapbrowser.common.dialogs; 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.BrowserCommonActivator; import org.apache.directory.studio.ldapbrowser.common.BrowserCommonConstants; 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.swt.SWT; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Shell; /** * This dialog is used to enter a LDAP filter. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class FilterWidgetDialog extends Dialog { /** The title */ private String title; /** The connection, used for attribute completion. */ private IBrowserConnection connection; /** The filter widget. */ private FilterWidget filterWidget; /** The filter. */ private String filter; /** The error message label. */ private Label errorMessageLabel; /** * Creates a new instance of FilterWidgetDialog. * * @param parentShell the parent shell * @param title the dialog's title * @param filter the inital filter * @param connection the connection, used for attribute completion */ public FilterWidgetDialog( Shell parentShell, String title, String filter, IBrowserConnection connection ) { super( parentShell ); this.title = title; this.filter = filter; this.connection = connection; setShellStyle( SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL | SWT.RESIZE ); } /** * Gets the filter. * * @return the filter */ public String getFilter() { return filter; } /** * {@inheritDoc} */ protected void configureShell( Shell newShell ) { super.configureShell( newShell ); newShell.setText( title ); newShell.setImage( BrowserCommonActivator.getDefault().getImage( BrowserCommonConstants.IMG_FILTER_EDITOR ) ); } /** * {@inheritDoc} */ protected void buttonPressed( int buttonId ) { if ( buttonId == IDialogConstants.OK_ID ) { filter = filterWidget.getFilter(); filterWidget.saveDialogSettings(); } // call super implementation super.buttonPressed( buttonId ); } /** * {@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 inner = new Composite( composite, SWT.NONE ); GridLayout gridLayout = new GridLayout( 2, false ); inner.setLayout( gridLayout ); gd = new GridData( GridData.FILL_BOTH | GridData.GRAB_HORIZONTAL ); gd.widthHint = convertHorizontalDLUsToPixels( IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH ); inner.setLayoutData( gd ); filterWidget = new FilterWidget( filter != null ? filter : "" ); //$NON-NLS-1$ filterWidget.createWidget( inner ); filterWidget.setBrowserConnection( connection ); filterWidget.setFocus(); filterWidget.addWidgetModifyListener( new WidgetModifyListener() { public void widgetModified( WidgetModifyEvent event ) { validate(); } } ); errorMessageLabel = BaseWidgetUtils.createLabel( inner, Messages .getString( "FilterWidgetDialog.EnterValidFilter" ), 2 ); //$NON-NLS-1$ validate(); return composite; } /** * Validates the filter. */ protected void validate() { if ( getButton( IDialogConstants.OK_ID ) != null ) { getButton( IDialogConstants.OK_ID ).setEnabled( filterWidget.getFilter() != null ); } errorMessageLabel.setText( filterWidget.getFilter() == null ? Messages .getString( "FilterWidgetDialog.EnterValidFilter" ) : "" ); //$NON-NLS-1$ //$NON-NLS-2$ } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/dialogs/MoveEntriesDialog.java
plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/dialogs/MoveEntriesDialog.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.ldapbrowser.common.dialogs; import org.apache.directory.api.ldap.model.name.Dn; 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.DnBuilderWidget; import org.apache.directory.studio.ldapbrowser.core.model.IEntry; import org.eclipse.jface.dialogs.Dialog; import org.eclipse.jface.dialogs.IDialogConstants; import org.eclipse.swt.SWT; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Shell; /** * Dialog to select and enter the new parent of some entries. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class MoveEntriesDialog extends Dialog implements WidgetModifyListener { /** The dialog title. */ private static final String DIALOG_TITLE = Messages.getString( "MoveEntriesDialog.MoveEntries" ); //$NON-NLS-1$ /** The entries to move. */ private IEntry[] entries; /** The dn builder widget. */ private DnBuilderWidget dnBuilderWidget; /** The ok button. */ private Button okButton; /** The parent Dn. */ private Dn parentDn; /** * Creates a new instance of MoveEntriesDialog. * * @param parentShell the parent shell * @param entries the entries */ public MoveEntriesDialog( Shell parentShell, IEntry[] entries ) { super( parentShell ); super.setShellStyle( super.getShellStyle() | SWT.RESIZE ); this.entries = entries; this.parentDn = null; } /** * @see org.eclipse.jface.window.Window#configureShell(org.eclipse.swt.widgets.Shell) */ protected void configureShell( Shell shell ) { super.configureShell( shell ); shell.setText( DIALOG_TITLE ); } /** * @see org.eclipse.jface.dialogs.Dialog#close() */ public boolean close() { dnBuilderWidget.removeWidgetModifyListener( this ); dnBuilderWidget.dispose(); return super.close(); } /** * @see org.eclipse.jface.dialogs.Dialog#okPressed() */ protected void okPressed() { parentDn = dnBuilderWidget.getParentDn(); dnBuilderWidget.saveDialogSettings(); super.okPressed(); } /** * @see org.eclipse.jface.dialogs.Dialog#createButtonsForButtonBar(org.eclipse.swt.widgets.Composite) */ protected void createButtonsForButtonBar( Composite parent ) { okButton = createButton( parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, true ); createButton( parent, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL, false ); } /** * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite) */ 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 ) * 3 / 2; composite.setLayoutData( gd ); BaseWidgetUtils.createLabel( composite, Messages.getString( "MoveEntriesDialog.MoveEntriesDescription" ), 1 ); //$NON-NLS-1$ dnBuilderWidget = new DnBuilderWidget( false, true ); dnBuilderWidget.addWidgetModifyListener( this ); dnBuilderWidget.createContents( composite ); dnBuilderWidget .setInput( entries[0].getBrowserConnection(), null, null, entries[0].getDn().getParent() ); applyDialogFont( composite ); return composite; } /** * @see org.apache.directory.studio.common.ui.widgets.WidgetModifyListener#widgetModified(org.apache.directory.studio.common.ui.widgets.WidgetModifyEvent) */ public void widgetModified( WidgetModifyEvent event ) { if ( okButton != null ) { okButton.setEnabled( dnBuilderWidget.getParentDn() != null ); } } /** * Gets the parent dn. * * @return the parent dn */ public Dn getParentDn() { return parentDn; } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/dialogs/RenameEntryDialog.java
plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/dialogs/RenameEntryDialog.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.ldapbrowser.common.dialogs; import java.util.Collection; import org.apache.commons.lang3.ArrayUtils; import org.apache.directory.api.ldap.model.name.Rdn; import org.apache.directory.api.ldap.model.schema.AttributeType; 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.BrowserCommonActivator; import org.apache.directory.studio.ldapbrowser.common.widgets.DnBuilderWidget; import org.apache.directory.studio.ldapbrowser.core.model.IEntry; 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.swt.SWT; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Shell; /** * A dialog to enter the new Rdn of an entry. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class RenameEntryDialog extends Dialog implements WidgetModifyListener { /** The "Delete old Rdn" dialog setting . */ private static final String DELETE_OLD_RDN_DIALOGSETTING_KEY = RenameEntryDialog.class.getName() + ".deleteOldRdn"; //$NON-NLS-1$ /** The dialog title. */ private static final String DIALOG_TITLE = Messages.getString( "RenameEntryDialog.RenameEntry" ); //$NON-NLS-1$ /** The entry to rename. */ private IEntry entry; /** The dn builder widget. */ private DnBuilderWidget dnBuilderWidget; /** The ok button. */ private Button okButton; /** The new rdn. */ private Rdn rdn; /** The initialization flag */ private boolean initialized = false; /** * Creates a new instance of RenameEntryDialog. * * @param parentShell the parent shell * @param entry the entry */ public RenameEntryDialog( Shell parentShell, IEntry entry ) { super( parentShell ); super.setShellStyle( super.getShellStyle() | SWT.RESIZE ); this.entry = entry; this.rdn = null; if ( BrowserCommonActivator.getDefault().getDialogSettings().get( DELETE_OLD_RDN_DIALOGSETTING_KEY ) == null ) { BrowserCommonActivator.getDefault().getDialogSettings().put( DELETE_OLD_RDN_DIALOGSETTING_KEY, true ); } } /** * @see org.eclipse.jface.window.Window#configureShell(org.eclipse.swt.widgets.Shell) */ protected void configureShell( Shell shell ) { super.configureShell( shell ); shell.setText( DIALOG_TITLE ); } /** * @see org.eclipse.jface.dialogs.Dialog#close() */ public boolean close() { dnBuilderWidget.removeWidgetModifyListener( this ); dnBuilderWidget.dispose(); return super.close(); } /** * @see org.eclipse.jface.dialogs.Dialog#okPressed() */ protected void okPressed() { rdn = dnBuilderWidget.getRdn(); super.okPressed(); } /** * @see org.eclipse.jface.dialogs.Dialog#createButtonsForButtonBar(org.eclipse.swt.widgets.Composite) */ protected void createButtonsForButtonBar( Composite parent ) { okButton = createButton( parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, true ); createButton( parent, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL, false ); } /** * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite) */ 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 ) * 3 / 2; composite.setLayoutData( gd ); BaseWidgetUtils.createLabel( composite, Messages.getString( "RenameEntryDialog.RenameEntryDescription" ), 1 ); //$NON-NLS-1$ dnBuilderWidget = new DnBuilderWidget( true, false ); dnBuilderWidget.addWidgetModifyListener( this ); dnBuilderWidget.createContents( composite ); Collection<AttributeType> allAtds = SchemaUtils.getAllAttributeTypeDescriptions( entry ); String[] allAttributeNames = SchemaUtils.getNames( allAtds ).toArray( ArrayUtils.EMPTY_STRING_ARRAY ); dnBuilderWidget.setInput( entry.getBrowserConnection(), allAttributeNames, entry.getRdn(), null ); applyDialogFont( composite ); initialized = true; return composite; } /** * @see org.apache.directory.studio.common.ui.widgets.WidgetModifyListener#widgetModified(org.apache.directory.studio.common.ui.widgets.WidgetModifyEvent) */ public void widgetModified( WidgetModifyEvent event ) { if ( okButton != null ) { okButton.setEnabled( dnBuilderWidget.getRdn() != null ); } // Forcing the redraw of the whole dialog if ( initialized && ( getShell() != null ) && ( !getShell().isDisposed() ) ) { getShell().pack(); } } /** * Gets the rdn. * * @return the rdn */ public Rdn getRdn() { return rdn; } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/dialogs/EntryExistsCopyStrategyDialogImpl.java
plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/dialogs/EntryExistsCopyStrategyDialogImpl.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.ldapbrowser.common.dialogs; import org.apache.directory.api.ldap.model.name.Dn; import org.apache.directory.api.ldap.model.name.Rdn; 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.DnBuilderWidget; import org.apache.directory.studio.ldapbrowser.core.jobs.EntryExistsCopyStrategyDialog; import org.apache.directory.studio.ldapbrowser.core.model.IBrowserConnection; 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.osgi.util.NLS; 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.Button; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Shell; /** * A dialog to select the copy strategy if an entry already exists. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class EntryExistsCopyStrategyDialogImpl extends Dialog implements EntryExistsCopyStrategyDialog { /** The dialog title. */ private String dialogTitle = Messages.getString( "EntryExistsCopyStrategyDialogImpl.SelectCopyStrategy" ); //$NON-NLS-1$ /** The break button. */ private Button breakButton; /** The ignore button. */ private Button ignoreButton; /** The overwrite button. */ private Button overwriteButton; /** The rename button. */ private Button renameButton; // // /** The remember check box. */ // private Button rememberCheckbox; /** The Dn builder widget. */ private DnBuilderWidget dnBuilderWidget; /** The new Rdn. */ private Rdn rdn; /** The strategy */ private EntryExistsCopyStrategy strategy; /** The remember flag */ private boolean isRememberStrategy; private IBrowserConnection browserConnection; private Dn dn; /** * Creates a new instance of ScopeDialog. * * @param parentShell the parent shell * @param dialogTitle the dialog title * @param multipleEntriesSelected the multiple entries selected */ public EntryExistsCopyStrategyDialogImpl( Shell parentShell ) { super( parentShell ); super.setShellStyle( super.getShellStyle() | SWT.RESIZE ); strategy = EntryExistsCopyStrategy.BREAK; } /** * @see org.eclipse.jface.window.Window#configureShell(org.eclipse.swt.widgets.Shell) */ protected void configureShell( Shell shell ) { super.configureShell( shell ); shell.setText( dialogTitle ); } /** * @see org.eclipse.jface.dialogs.Dialog#okPressed() */ protected void okPressed() { rdn = null; // isRememberStrategy = rememberCheckbox.getSelection() && rememberCheckbox.isEnabled(); if ( breakButton.getSelection() ) { strategy = EntryExistsCopyStrategy.BREAK; } else if ( ignoreButton.getSelection() ) { strategy = EntryExistsCopyStrategy.IGNORE_AND_CONTINUE; } else if ( overwriteButton.getSelection() ) { strategy = EntryExistsCopyStrategy.OVERWRITE_AND_CONTINUE; } else if ( renameButton.getSelection() ) { strategy = EntryExistsCopyStrategy.RENAME_AND_CONTINUE; rdn = dnBuilderWidget.getRdn(); } super.okPressed(); } /** * @see org.eclipse.jface.dialogs.Dialog#createButtonsForButtonBar(org.eclipse.swt.widgets.Composite) */ protected void createButtonsForButtonBar( Composite parent ) { createButton( parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, true ); createButton( parent, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL, false ); } /** * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite) */ protected Control createDialogArea( Composite parent ) { Composite composite = ( Composite ) super.createDialogArea( parent ); GridData gd = new GridData( GridData.FILL_BOTH ); composite.setLayoutData( gd ); String text = NLS.bind( Messages.getString( "EntryExistsCopyStrategyDialogImpl.SelectCopyStrategyDescription" ), dn.getName() ); //$NON-NLS-1$ BaseWidgetUtils.createLabel( composite, text, 1 ); Composite group2 = BaseWidgetUtils.createGroup( composite, "", 1 ); //$NON-NLS-1$ Composite group = BaseWidgetUtils.createColumnContainer( group2, 2, 1 ); SelectionListener listener = new SelectionAdapter() { public void widgetSelected( SelectionEvent e ) { validate(); } }; breakButton = BaseWidgetUtils.createRadiobutton( group, Messages .getString( "EntryExistsCopyStrategyDialogImpl.StopCopyProcess" ), 2 ); //$NON-NLS-1$ breakButton.setSelection( true ); breakButton.addSelectionListener( listener ); ignoreButton = BaseWidgetUtils.createRadiobutton( group, Messages .getString( "EntryExistsCopyStrategyDialogImpl.IgnoreEntryAndContinue" ), 2 ); //$NON-NLS-1$ ignoreButton.addSelectionListener( listener ); overwriteButton = BaseWidgetUtils.createRadiobutton( group, Messages .getString( "EntryExistsCopyStrategyDialogImpl.OverwriteEntryAndContinue" ), 2 ); //$NON-NLS-1$ overwriteButton.addSelectionListener( listener ); renameButton = BaseWidgetUtils.createRadiobutton( group, Messages .getString( "EntryExistsCopyStrategyDialogImpl.RenameEntryAndContinue" ), 2 ); //$NON-NLS-1$ renameButton.addSelectionListener( listener ); BaseWidgetUtils.createRadioIndent( group, 1 ); dnBuilderWidget = new DnBuilderWidget( true, false ); dnBuilderWidget.addWidgetModifyListener( new WidgetModifyListener() { public void widgetModified( WidgetModifyEvent event ) { validate(); } } ); dnBuilderWidget.createContents( group ); dnBuilderWidget.setInput( browserConnection, SchemaUtils.getNamesAsArray( browserConnection.getSchema() .getAttributeTypeDescriptions() ), dn.getRdn(), null ); // rememberCheckbox = BaseWidgetUtils.createCheckbox( composite, "Remember decision", 2 ); validate(); applyDialogFont( composite ); return composite; } private void validate() { if ( renameButton.getSelection() ) { dnBuilderWidget.setEnabled( true ); getButton( IDialogConstants.OK_ID ).setEnabled( dnBuilderWidget.getRdn() != null ); } else { dnBuilderWidget.setEnabled( false ); } // rememberCheckbox.setEnabled( overwriteButton.getSelection() || ignoreButton.getSelection() ); } /** * {@inheritDoc} */ public int open() { final int[] result = new int[1]; Display.getDefault().syncExec( new Runnable() { public void run() { result[0] = EntryExistsCopyStrategyDialogImpl.super.open(); } } ); return result[0]; } /** * {@inheritDoc} */ public EntryExistsCopyStrategy getStrategy() { return strategy; } /** * {@inheritDoc} */ public Rdn getRdn() { return rdn; } /** * {@inheritDoc} */ public boolean isRememberSelection() { return isRememberStrategy; } /** * {@inheritDoc} */ public void setExistingEntry( IBrowserConnection browserConnection, Dn dn ) { this.browserConnection = browserConnection; this.dn = dn; } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/dialogs/FilterDialog.java
plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/dialogs/FilterDialog.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.ldapbrowser.common.dialogs; import org.apache.directory.studio.ldapbrowser.common.BrowserCommonActivator; import org.apache.directory.studio.ldapbrowser.common.BrowserCommonConstants; import org.apache.directory.studio.ldapbrowser.common.filtereditor.FilterSourceViewerConfiguration; import org.apache.directory.studio.ldapbrowser.core.model.IBrowserConnection; import org.apache.directory.studio.ldapbrowser.core.model.filter.parser.LdapFilterParser; import org.eclipse.jface.dialogs.Dialog; import org.eclipse.jface.dialogs.IDialogConstants; 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.VerticalRuler; 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; /** * Dialog to edit a filter in a text source viewer with syntax highlighting * and content assistent. It also provides a button to format the filter. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class FilterDialog extends Dialog { /** The default dialog title. */ private static final String DIALOG_TITLE = Messages.getString( "FilterDialog.FilterEditor" ); //$NON-NLS-1$ /** The button ID for the format button. */ private static final int FORMAT_BUTTON_ID = 987654321; /** The dialog title. */ private String title; /** The browser connection. */ private IBrowserConnection browserConnection; /** The source viewer. */ private SourceViewer sourceViewer; /** The filter source viewer configuration. */ private FilterSourceViewerConfiguration configuration; /** The filter parser. */ private LdapFilterParser parser; /** The filter. */ private String filter; /** * Creates a new instance of FilterDialog. * * @param parentShell the parent shell * @param title the title * @param filter the initial filter * @param brwoserConnection the browser connection */ public FilterDialog( Shell parentShell, String title, String filter, IBrowserConnection brwoserConnection ) { super( parentShell ); this.title = title; this.filter = filter; this.browserConnection = brwoserConnection; this.parser = new LdapFilterParser(); setShellStyle( SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL | SWT.RESIZE ); } /** * Gets the filter. * * @return the filter */ public String getFilter() { return filter; } /** * @see org.eclipse.jface.window.Window#configureShell(org.eclipse.swt.widgets.Shell) */ protected void configureShell( Shell newShell ) { super.configureShell( newShell ); newShell.setText( title != null ? title : DIALOG_TITLE ); newShell.setImage( BrowserCommonActivator.getDefault().getImage( BrowserCommonConstants.IMG_FILTER_EDITOR ) ); } /** * @see org.eclipse.jface.dialogs.Dialog#buttonPressed(int) */ protected void buttonPressed( int buttonId ) { if ( buttonId == IDialogConstants.OK_ID ) { parser.parse( sourceViewer.getDocument().get() ); filter = parser.getModel().toString(); } else if ( buttonId == FORMAT_BUTTON_ID ) { IRegion region = new Region( 0, sourceViewer.getDocument().getLength() ); configuration.getContentFormatter( sourceViewer ).format( sourceViewer.getDocument(), region ); } // call super implementation super.buttonPressed( buttonId ); } /** * @see org.eclipse.jface.dialogs.Dialog#createButtonBar(org.eclipse.swt.widgets.Composite) */ protected Control createButtonBar( Composite parent ) { Composite composite = ( Composite ) super.createButtonBar( parent ); super.createButton( composite, FORMAT_BUTTON_ID, Messages.getString( "FilterDialog.Format" ), false ); //$NON-NLS-1$ return composite; } /** * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite) */ protected Control createDialogArea( Composite parent ) { // Composite 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 = convertHorizontalDLUsToPixels( IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH ); composite.setLayoutData( gd ); // create and configure source viewer sourceViewer = new SourceViewer( composite, new VerticalRuler( 0 ), SWT.H_SCROLL | SWT.V_SCROLL ); sourceViewer.getControl().setLayoutData( new GridData( GridData.FILL_BOTH ) ); configuration = new FilterSourceViewerConfiguration( parser, browserConnection ); sourceViewer.configure( configuration ); // set document IDocument document = new Document( filter ); sourceViewer.setDocument( document ); // preformat IRegion region = new Region( 0, sourceViewer.getDocument().getLength() ); configuration.getContentFormatter( sourceViewer ).format( sourceViewer.getDocument(), region ); // set focus to the source viewer sourceViewer.getTextWidget().setFocus(); return composite; } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/dialogs/SimulateRenameDialogImpl.java
plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/dialogs/SimulateRenameDialogImpl.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.ldapbrowser.common.dialogs; import org.apache.directory.api.ldap.model.name.Dn; import org.apache.directory.studio.common.ui.widgets.BaseWidgetUtils; import org.apache.directory.studio.ldapbrowser.core.jobs.SimulateRenameDialog; import org.apache.directory.studio.ldapbrowser.core.model.IBrowserConnection; import org.eclipse.jface.dialogs.Dialog; import org.eclipse.jface.dialogs.IDialogConstants; import org.eclipse.osgi.util.NLS; 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.Display; import org.eclipse.swt.widgets.Shell; /** * A dialog used to ask the user to simulate the rename operation by * recursively searching/adding/deleting. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class SimulateRenameDialogImpl extends Dialog implements SimulateRenameDialog { /** The dialog title. */ private String dialogTitle = Messages.getString( "SimulateRenameDialogImpl.SimulateRename" ); //$NON-NLS-1$ /** The simulate rename flag */ private boolean isSimulateRename; /** The browser connection. */ private IBrowserConnection browserConnection; /** The old Dn. */ private Dn oldDn; /** The new Dn. */ private Dn newDn; /** * Creates a new instance of ScopeDialog. * * @param parentShell the parent shell * @param dialogTitle the dialog title * @param multipleEntriesSelected the multiple entries selected */ public SimulateRenameDialogImpl( Shell parentShell ) { super( parentShell ); super.setShellStyle( super.getShellStyle() | SWT.RESIZE ); } /** * {@inheritDoc} */ protected void configureShell( Shell shell ) { super.configureShell( shell ); shell.setText( dialogTitle ); } /** * {@inheritDoc} */ protected void okPressed() { isSimulateRename = true; super.okPressed(); } /** * {@inheritDoc} */ protected void createButtonsForButtonBar( Composite parent ) { createButton( parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, false ); createButton( parent, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL, false ); } /** * {@inheritDoc} */ protected Control createDialogArea( Composite parent ) { Composite composite = ( Composite ) super.createDialogArea( parent ); GridData gd = new GridData( GridData.FILL_BOTH ); composite.setLayoutData( gd ); Composite innerComposite = BaseWidgetUtils.createColumnContainer( composite, 1, 1 ); gd = new GridData( GridData.FILL_BOTH ); innerComposite.setLayoutData( gd ); String text1 = NLS .bind( Messages.getString( "SimulateRenameDialogImpl.SimulateRenameDescription1" ), oldDn.getName(), newDn.getName() ); //$NON-NLS-1$ BaseWidgetUtils.createLabel( innerComposite, text1, 1 ); String text2 = NLS.bind( Messages.getString( "SimulateRenameDialogImpl.SimulateRenameDescription2" ), //$NON-NLS-1$ browserConnection.getConnection().getName() ); BaseWidgetUtils.createLabel( innerComposite, text2, 1 ); String text3 = Messages.getString( "SimulateRenameDialogImpl.SimulateButton" ); //$NON-NLS-1$ BaseWidgetUtils.createLabel( innerComposite, text3, 1 ); applyDialogFont( composite ); return composite; } /** * {@inheritDoc} */ public int open() { final int[] result = new int[1]; Display.getDefault().syncExec( new Runnable() { public void run() { result[0] = SimulateRenameDialogImpl.super.open(); } } ); return result[0]; } /** * {@inheritDoc} */ public void setEntryInfo( IBrowserConnection browserConnection, Dn oldDn, Dn newDn ) { this.browserConnection = browserConnection; this.oldDn = oldDn; this.newDn = newDn; } /** * {@inheritDoc} */ public boolean isSimulateRename() { return isSimulateRename; } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false