Package org.apache.directory.studio.ldapbrowser.core.model

Examples of org.apache.directory.studio.ldapbrowser.core.model.ISearch


     *
     * This viewer selects the updated search.
     */
    public void searchUpdated( SearchUpdateEvent searchUpdateEvent )
    {
        ISearch search = searchUpdateEvent.getSearch();
        viewer.setSelection( StructuredSelection.EMPTY );
        viewer.refresh();

        if ( search instanceof IContinuation )
        {
            viewer.setSelection( new StructuredSelection( search ), true );
        }
        else if ( search.getBrowserConnection().getSearchManager().getSearches().contains( search ) )
        {
            viewer.setSelection( new StructuredSelection( search ), true );
        }
        else if ( search.getBrowserConnection().getSearchManager().getQuickSearch() == search )
        {
            viewer.setSelection( new StructuredSelection( search ), true );
        }
        else
        {
View Full Code Here


    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$
        }
View Full Code Here

    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 )
        {
            searchInput.setSearchResults( null );
            new StudioBrowserJob( new SearchRunnable( new ISearch[]
                { searchInput } ) ).execute();
        }
    }
View Full Code Here

    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;
    }
View Full Code Here

        {
            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 getImageByObjectClass( entry );
        }
        else if ( obj instanceof StudioRunnableWithProgress )
        {
            StudioRunnableWithProgress runnable = ( StudioRunnableWithProgress ) 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 )
View Full Code Here

        monitor.beginTask( " ", searches.length + 1 ); //$NON-NLS-1$
        monitor.reportProgress( " " ); //$NON-NLS-1$

        for ( int pi = 0; pi < searches.length; pi++ )
        {
            ISearch search = searches[pi];
            ISearch searchToPerform = searchesToPerform[pi];

            monitor.setTaskName( BrowserCoreMessages.bind( BrowserCoreMessages.jobs__search_task, new String[]
                { search.getName() } ) );
            monitor.worked( 1 );

            if ( search.getBrowserConnection() != null )
            {
                // reset search results
                search.setSearchResults( new ISearchResult[0] );
                search.getResponseControls().clear();
                search.setNextPageSearchRunnable( null );
                search.setTopPageSearchRunnable( null );
                searchToPerform.setSearchResults( new ISearchResult[0] );
                searchToPerform.setNextPageSearchRunnable( null );
                searchToPerform.setTopPageSearchRunnable( null );
                searchToPerform.getResponseControls().clear();

                do
                {
                    // perform search
                    searchAndUpdateModel( searchToPerform.getBrowserConnection(), searchToPerform, monitor );

                    if ( search != searchToPerform )
                    {
                        // merge search results
                        ISearchResult[] sr1 = search.getSearchResults();
                        ISearchResult[] sr2 = searchToPerform.getSearchResults();
                        ISearchResult[] sr = new ISearchResult[sr1.length + sr2.length];
                        System.arraycopy( sr1, 0, sr, 0, sr1.length );
                        System.arraycopy( sr2, 0, sr, sr1.length, sr2.length );
                        search.setSearchResults( sr );
                    }
                    else
                    {
                        // set search results
                        search.setSearchResults( searchToPerform.getSearchResults() );
                    }

                    // check response controls
                    ISearch clonedSearch = ( ISearch ) searchToPerform.clone();
                    clonedSearch.getResponseControls().clear();
                    StudioPagedResultsControl sprResponseControl = null;
                    StudioPagedResultsControl sprRequestControl = null;
                    for ( StudioControl responseControl : searchToPerform.getResponseControls() )
                    {
                        if ( responseControl instanceof StudioPagedResultsControl )
                        {
                            sprResponseControl = ( StudioPagedResultsControl ) responseControl;
                        }
                    }
                    for ( Iterator<StudioControl> it = clonedSearch.getControls().iterator(); it.hasNext(); )
                    {
                        StudioControl requestControl = it.next();
                        if ( requestControl instanceof StudioPagedResultsControl )
                        {
                            sprRequestControl = ( StudioPagedResultsControl ) requestControl;
                            it.remove();
                        }
                    }
                    searchToPerform = null;

                    // paged search
                    if ( sprResponseControl != null && sprRequestControl != null )
                    {
                        StudioPagedResultsControl nextSpsc = new StudioPagedResultsControl(
                            sprRequestControl.getSize(), sprResponseControl.getCookie(),
                            sprRequestControl.isCritical(), sprRequestControl.isScrollMode() );
                        ISearch nextPageSearch = ( ISearch ) clonedSearch.clone();
                        nextPageSearch.getResponseControls().clear();
                        nextPageSearch.getControls().add( nextSpsc );
                        if ( sprRequestControl.isScrollMode() )
                        {
                            if ( sprRequestControl.getCookie() != null )
                            {
                                // create top page search runnable, same as original search
                                ISearch topPageSearch = ( ISearch ) search.clone();
                                topPageSearch.getResponseControls().clear();
                                SearchRunnable topPageSearchRunnable = new SearchRunnable( search, topPageSearch );
                                search.setTopPageSearchRunnable( topPageSearchRunnable );
                            }
                            if ( sprResponseControl.getCookie() != null )
                            {
View Full Code Here

            browserConnection = getSelectedSearches()[0].getBrowserConnection();
        }

        if ( browserConnection != null )
        {
            ISearch clone = null;
            for ( ISearch search : searches )
            {
                SearchParameter searchParameter = ( SearchParameter ) search.getSearchParameter().clone();
                clone = new Search( browserConnection, searchParameter );
                browserConnection.getSearchManager().addSearch( clone );
            }

            if ( searches.length == 1 )
            {
                IAdaptable element = ( IAdaptable ) clone;
                String pageId = BrowserCommonConstants.PROP_SEARCH;
                String title = clone.getName();

                PreferenceDialog dialog = PreferencesUtil.createPropertyDialogOn( getShell(), element, pageId, null,
                    null );
                if ( dialog != null )
                {
View Full Code Here

     * @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 != null && !selection.isEmpty() && selection instanceof StructuredSelection )
        {
            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;
View Full Code Here

                            readIn.read( connectionId );
                            connection = BrowserCorePlugin.getDefault().getConnectionManager()
                                .getBrowserConnectionById( new String( connectionId, "UTF-8" ) ); //$NON-NLS-1$
                        }

                        ISearch search = null;
                        if ( readIn.available() > 1 && connection != null )
                        {
                            int size = readIn.readInt();
                            if ( size == 0 )
                            {
View Full Code Here

    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$
        }
View Full Code Here

TOP

Related Classes of org.apache.directory.studio.ldapbrowser.core.model.ISearch

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.