Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Copyright 2007 Alin Dreghiciu.
   *
   * Licensed  under the  Apache License,  Version 2.0  (the "License");
   * you may not use  this file  except in  compliance with the License.
   * You may obtain a copy of the License at
   *
   *   http://www.apache.org/licenses/LICENSE-2.0
   *
  * Unless required by applicable law or agreed to in writing, software
  * distributed  under the  License is distributed on an "AS IS" BASIS,
  * WITHOUT  WARRANTIES OR CONDITIONS  OF ANY KIND, either  express  or
  * implied.
  *
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
 package org.ops4j.pax.cursor.ui;
 
 import java.io.File;
 import java.util.List;
 import java.util.Map;
 import  org.eclipse.core.runtime.CoreException;
 import  org.eclipse.debug.core.ILaunchConfiguration;
 import  org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
 import  org.eclipse.debug.ui.ILaunchConfigurationTab;
 import  org.eclipse.jface.dialogs.InputDialog;
 import  org.eclipse.jface.dialogs.MessageDialog;
 import  org.eclipse.jface.viewers.CellEditor;
 import  org.eclipse.jface.viewers.CheckStateChangedEvent;
 import  org.eclipse.jface.viewers.CheckboxCellEditor;
 import  org.eclipse.jface.viewers.CheckboxTableViewer;
 import  org.eclipse.jface.viewers.DoubleClickEvent;
 import  org.eclipse.jface.viewers.ICheckStateListener;
 import  org.eclipse.jface.viewers.IDoubleClickListener;
 import  org.eclipse.jface.viewers.ISelectionChangedListener;
 import  org.eclipse.jface.viewers.IStructuredSelection;
 import  org.eclipse.jface.viewers.SelectionChangedEvent;
 import  org.eclipse.jface.viewers.TextCellEditor;
 import  org.eclipse.jface.window.Window;
 import  org.eclipse.pde.internal.ui.PDEUIMessages;
 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.DirectoryDialog;
 import  org.eclipse.swt.widgets.FileDialog;
 import  org.eclipse.swt.widgets.Group;
 import  org.eclipse.swt.widgets.Table;
 import  org.eclipse.swt.widgets.TableColumn;
 import  org.eclipse.swt.widgets.TableItem;
Provisioning Composite of Pax Runner Eclipse Plugin (bottom group).

Author(s):
Alin Dreghiciu
Since:
0.2.0, December 16, 2007
 
 public class ProvisionBlock
     extends CursorTabBlock
 {
 
     private final CheckboxTableViewer m_tableViewer;
     private final Button m_editButton;
     private final Button m_deleteButton;
 
     private File m_lastUsedDir;

    

See also:
Composite.Composite(Composite, int)
 
     public ProvisionBlock( Composite parentint style )
     {
         superparentstyle );
         final GridLayout gridLayout = new GridLayout();
         setLayout( gridLayout );
 
         final Group provisioningGroup = new Group( this, SWT.NONE );
         provisioningGroup.setLayoutData( new GridData( SWT.FILL, SWT.FILL, truetrue ) );
         provisioningGroup.setText( "Provisioning:" );
         final GridLayout provisioningGridLayout = new GridLayout();
         provisioningGridLayout.marginWidth = 0;
         provisioningGridLayout.marginHeight = 0;
         provisioningGridLayout.numColumns = 2;
         provisioningGroup.setLayout( provisioningGridLayout );
 
         final Composite tableComposite = new Composite( provisioningGroup, SWT.NONE );
         final GridData tableGridData = new GridData( SWT.FILL, SWT.FILL, truetrue );
         tableComposite.setLayoutData( tableGridData );
         final GridLayout tableGridLayout = new GridLayout();
        tableGridLayout.marginWidth = 0;
        tableGridLayout.marginHeight = 0;
        tableComposite.setLayout( tableGridLayout );
         = CheckboxTableViewer.newCheckList( tableComposite, SWT.MULTI | SWT.FULL_SELECTION | SWT.BORDER );
        .setContentProvider( new ProvisionContentProvider() );
        .setLabelProvider( new ProvisionLabelProvider() );
        .addCheckStateListener(
            new ICheckStateListener()
            {
                public void checkStateChangedfinal CheckStateChangedEvent event )
                {
                    notifyUpdate();
                }
            }
        );
        .addSelectionChangedListener(
            new ISelectionChangedListener()
            {
                public void selectionChanged( SelectionChangedEvent event )
                {
                    onTableSelectionChangedevent );
                }
            }
        );
        .addDoubleClickListener( new IDoubleClickListener()
        {
            public void doubleClick( DoubleClickEvent event )
            {
                if( !.getSelection().isEmpty() )
                {
                    onEditButtonSelected();
                }
            }
        }
        );
        final Table table = .getTable();
        table.setLinesVisible( true );
        table.setHeaderVisible( true );
        table.setLayoutData( new GridData( SWT.FILL, SWT.FILL, truetrue ) );
        final TableColumn urlTableColumn = new TableColumn( table, SWT.NONE );
        urlTableColumn.setWidth( 425 );
        urlTableColumn.setText( "Provision from" );
        final TableColumn startTableColumn = new TableColumn( table, SWT.CENTER );
        startTableColumn.setWidth( 50 );
        startTableColumn.setText( "Start" );
        final TableColumn levelTableColumn = new TableColumn( table, SWT.CENTER );
        levelTableColumn.setWidth( 70 );
        levelTableColumn.setText( "Level" );
        final TableColumn updateTableColumn = new TableColumn( table, SWT.CENTER );
        updateTableColumn.setWidth( 50 );
        updateTableColumn.setText( "Update" );
        final ProvisionCellModifier cellModifier = new ProvisionCellModifier();
        cellModifier.setModifyListener(
            new ProvisionCellModifier.ModifyListener()
            {
                public void modifiedObject element )
                {
                    .update( elementnull );
                    notifyUpdate();
                }
            }
        );
        .setCellModifier( cellModifier );
        .setCellEditors(
            new CellEditor[]
                {
                    null,
                    new CheckboxCellEditor( table ),
                    new TextCellEditor( table ),
                    new CheckboxCellEditor( table )
                }
        );
        .setColumnProperties( new String[]{ "url""start""level""update" } );
        final Composite buttonsComposite = new Composite( provisioningGroup, SWT.NONE );
        final GridData butonsGridData = new GridData( SWT.LEFT, SWT.TOP, falsefalse );
        buttonsComposite.setLayoutData( butonsGridData );
        buttonsComposite.setLayout( new GridLayout() );
        final Button addButton = new Button( buttonsComposite, SWT.NONE );
        addButton.setLayoutData( new GridData( SWT.FILL, SWT.CENTER, falsefalse ) );
        addButton.addSelectionListener(
            new SelectionAdapter()
            {
                public void widgetSelectedfinal SelectionEvent e )
                {
                    onAddButtonSelected();
                }
            }
        );
        addButton.setText( "Add URL" );
        final Button addBundleButton = new Button( buttonsComposite, SWT.NONE );
        addBundleButton.setLayoutData( new GridData( SWT.FILL, SWT.CENTER, falsefalse ) );
        addBundleButton.addSelectionListener(
            new SelectionAdapter()
            {
                public void widgetSelectedfinal SelectionEvent e )
                {
                    onAddSingleFileButtonSelected"scan-bundle"new String[]{ "*.jar""*.*" },
                                                   new String[]{ "Any Jar""Any File" }
                    );
                }
            }
        );
        addBundleButton.setText( "Add Bundle..." );
        final Button addFileButton = new Button( buttonsComposite, SWT.NONE );
        addFileButton.setLayoutData( new GridData( SWT.FILL, SWT.CENTER, falsefalse ) );
        addFileButton.addSelectionListener(
            new SelectionAdapter()
            {
                public void widgetSelectedfinal SelectionEvent e )
                {
                    onAddSingleFileButtonSelected"scan-file"new String[]{ "*.bundles""*.txt""*.*" },
                                                   new String[]{ "Provision File""TXT Provision File""Any File" }
                    );
                }
            }
        );
        addFileButton.setText( "Add File..." );
        final Button addPomButton = new Button( buttonsComposite, SWT.NONE );
        addPomButton.setLayoutData( new GridData( SWT.FILL, SWT.CENTER, falsefalse ) );
        addPomButton.addSelectionListener(
            new SelectionAdapter()
            {
                public void widgetSelectedfinal SelectionEvent e )
                {
                    onAddSingleFileButtonSelected"scan-pom"new String[]{ "pom.xml""*.pom""*.*" },
                                                   new String[]{ "Maven POM""Maven Repository POM""Any File" }
                    );
                }
            }
        );
        addPomButton.setText( "Add POM..." );
        final Button addDirButton = new Button( buttonsComposite, SWT.NONE );
        addDirButton.setLayoutData( new GridData( SWT.FILL, SWT.CENTER, falsefalse ) );
        addDirButton.addSelectionListener(
            new SelectionAdapter()
            {
                public void widgetSelectedfinal SelectionEvent e )
                {
                    onAddDirButtonSelected();
                }
            }
        );
        addDirButton.setText( "Add Dir..." );
        final Button addMavenButton = new Button( buttonsComposite, SWT.NONE );
        addMavenButton.setLayoutData( new GridData( SWT.FILL, SWT.CENTER, falsefalse ) );
        addMavenButton.addSelectionListener(
            new SelectionAdapter()
            {
                public void widgetSelectedfinal SelectionEvent e )
                {
                    onAddMavenButtonSelected();
                }
            }
        );
        addMavenButton.setText( "Add Maven..." );
         = new Button( buttonsComposite, SWT.NONE );
        .setLayoutData( new GridData( SWT.FILL, SWT.CENTER, falsefalse ) );
        .setEnabled( false );
        .addSelectionListener(
            new SelectionAdapter()
            {
                public void widgetSelectedfinal SelectionEvent e )
                {
                    onEditButtonSelected();
                }
            }
        );
        .setText( "Edit..." );
         = new Button( buttonsComposite, SWT.NONE );
        .setLayoutData( new GridData( SWT.FILL, SWT.CENTER, falsefalse ) );
        .setEnabled( false );
        .addSelectionListener(
            new SelectionAdapter()
            {
                public void widgetSelectedfinal SelectionEvent e )
                {
                    onRemoveButtonSelected();
                }
            }
        );
        .setText( "Delete" );
    }

    
Handles add button push.
    protected void onAddButtonSelected()
    {
        InputDialog dialog = new InputDialog( getShell(), "Add bundle from URL""Bundle URL (e.g. OBR):"nullnull );
        ifdialog.open() != Window.OK )
        {
            return;
        }
        addURLdialog.getValue() );
    }

    
Handles add bundle/file/pom button push.
    private void onAddSingleFileButtonSelectedfinal String scannerfinal String[] filterExtensions,
                                                final String[] filterNames )
    {
        final FileDialog fileDialog = new FileDialog( getShell(), SWT.OPEN );
        fileDialog.setText( "File Selection" );
        fileDialog.setFilterExtensions( filterExtensions );
        fileDialog.setFilterNames( filterNames );
        if != null )
        {
            fileDialog.setFilterPath( .getAbsolutePath() );
        }
        final String selected = fileDialog.open();
        ifselected != null )
        {
            final File selectedFile = new Fileselected );
            ifselectedFile.exists() && selectedFile.isFile() )
            {
                 = selectedFile.getParentFile();
                try
                {
                    addURLscanner + ":" + selectedFile.getCanonicalFile().toURL().toExternalForm() );
                }
                catchMalformedURLException ignore )
                {
                    // DebugUIPlugin.log(ignore.getMessage());
                }
                catchIOException ignore )
                {
                    // DebugUIPlugin.log(ignore.getMessage());
                }
            }
        }
    }

    
Handles add dir button push.
    protected void onAddDirButtonSelected()
    {
        final DirectoryDialog dialog = new DirectoryDialog( getShell() );
        dialog.setText( PDEUIMessages.BaseBlock_dirSelection );
        dialog.setMessage( PDEUIMessages.BaseBlock_dirChoose );
        if != null )
        {
            dialog.setFilterPath( .getAbsolutePath() );
        }
        final String selected = dialog.open();
        ifselected != null )
        {
            final File selectedFile = new Fileselected );
            ifselectedFile.exists() && selectedFile.isDirectory() )
            {
                 = selectedFile;
                try
                {
                    addURL"scan-dir:" + selectedFile.getCanonicalFile().toURL().toExternalForm() );
                }
                catchMalformedURLException ignore )
                {
                    // DebugUIPlugin.log(ignore.getMessage());
                }
                catchIOException ignore )
                {
                    // DebugUIPlugin.log(ignore.getMessage());
                }
            }
        }
    }
    private void onAddMavenButtonSelected()
    {
        MessageDialog.openInformation( getShell(), "Information",
                                       "Not yet implemented, but will allow selection of a Maven artifact from local or remote repository"
        );
    }

    
Handles edit button push.
    protected void onEditButtonSelected()
    {
        final IStructuredSelection sel = (IStructuredSelection) .getSelection();
        ifsel == null || sel.isEmpty() )
        {
            return;
        }
        final ProvisionURL provisionURL = (ProvisionURLsel.iterator().next();
        InputDialog dialog =
            new InputDialog( getShell(), "Add""Provision from"provisionURL.getUrl(), null );
        ifdialog.open() != Window.OK )
        {
            return;
        }
        updateURLprovisionURLdialog.getValue() );
    }

    
Handles delete button push.
    private void onRemoveButtonSelected()
    {
        final IStructuredSelection sel = (IStructuredSelection) .getSelection();
        ifsel == null || sel.isEmpty() )
        {
            return;
        }
        .getControl().setRedraw( false );
        forIterator i = sel.iterator(); i.hasNext(); )
        {
            .remove( i.next() );
        }
        .getControl().setRedraw( true );
    }

    
Handles a change on a selection in provision table.

Parameters:
event selection changed event
    private void onTableSelectionChangedfinal SelectionChangedEvent event )
    {
        int size = ( (IStructuredSelection) event.getSelection() ).size();
        .setEnabled( size == 1 );
        .setEnabled( size > 0 );
    }

    
Creates a provision url.

Parameters:
url created url
    private void addURLfinal String url )
    {
        ProvisionURL provisionURL = new ProvisionURLurltruetruenullfalse );
        .add( provisionURL );
        .setChecked( provisionURLprovisionURL.isSelected() );
        notifyUpdate();
    }

    
Updates a provision url after edit.

Parameters:
provisionURL to be updated
url new url
    private void updateURLfinal ProvisionURL provisionURLfinal String url )
    {
        provisionURL.setUrlurl );
        .update( provisionURLnull );
        notifyUpdate();
    }

    
Initialize block.

See also:
ILaunchConfigurationTab.initializeFrom(ILaunchConfiguration)
    public void initializeFromfinal ILaunchConfiguration configuration )
    {
        try
        {
            final Map toRestore = (Mapconfiguration.getAttribute( .new HashMap() );
            final List provisionURLs = new ArrayList();
            final List selectedURLs = new ArrayList();
            forIterator iterator = toRestore.entrySet().iterator(); iterator.hasNext(); )
            {
                final Map.Entry entry = (Map.Entryiterator.next();
                final ProvisionURL provisionURL = new ProvisionURL();
                provisionURL.setUrl( (Stringentry.getKey() );
                ifentry.getValue() != null )
                {
                    final String[] options = ( (Stringentry.getValue() ).split"@" );
                    // first option: selected - boolean
                    ifoptions.length >= 1 )
                    {
                        provisionURL.setSelected( Boolean.valueOfoptions[ 0 ] ).booleanValue() );
                    }
                    // second option: start - boolean
                    ifoptions.length >= 2 )
                    {
                        provisionURL.setStart( Boolean.valueOfoptions[ 1 ] ).booleanValue() );
                    }
                    // third option: start level - integer ("null" if not specified)
                    ifoptions.length >= 3 && !options[ 2 ].equals"null" ) )
                    {
                        try
                        {
                            provisionURL.setStartLevel( Integer.valueOfoptions[ 2 ] ) );
                        }
                        catchNumberFormatException ignore )
                        {
                            // ignore. actually it should not happen
                        }
                    }
                    // forth option: update - boolean
                    ifoptions.length >= 4 )
                    {
                        provisionURL.setUpdate( Boolean.valueOfoptions[ 3 ] ).booleanValue() );
                    }
                }
                provisionURLs.addprovisionURL );
                ifprovisionURL.isSelected() )
                {
                    selectedURLs.addprovisionURL );
                }
            }
            .setInput( provisionURLs );
            ifselectedURLs.size() > 0 )
            {
                .setCheckedElements( selectedURLs.toArray() );
            }
        }
        catch( CoreException ignore )
        {
            // DebugUIPlugin.log(ignore.getStatus());
        }
    }

    
Saves block configurations attributes.
It will save a map where the key is the url and the value are the other options as selected@start@start_level@update.

See also:
ILaunchConfigurationTab.performApply(ILaunchConfigurationWorkingCopy)
    public void performApplyfinal ILaunchConfigurationWorkingCopy configuration )
    {
        // finally, save arguments list
        List arguments = null;
        try
        {
            arguments = configuration.getAttribute( ., (Listnull );
        }
        catch( CoreException ignore )
        {
            // DebugUIPlugin.log(ignore.getStatus());;
        }
        final TableItem[] items = .getTable().getItems();
        Map toSave = null;
        ifitems != null && items.length > 0 )
        {
            ifarguments == null )
            {
                arguments = new ArrayList();
            }
            toSave = new HashMapitems.length );
            forint i = 0; i < items.length; i++ )
            {
                final ProvisionURL provisionURL = (ProvisionURLitemsi ].getData();
                StringBuffer options = new StringBuffer()
                    .append.getChecked( provisionURL ) )
                    .append( "@" ).append( provisionURL.isStart() )
                    .append( "@" ).append( provisionURL.getStartLevel() )
                    .append( "@" ).append( provisionURL.isUpdate() );
                toSave.putprovisionURL.getUrl(), options.toString() );
                ifprovisionURL.isSelected() )
                {
                    final StringBuffer provisionFrom = new StringBufferprovisionURL.getUrl() );
                    ifprovisionURL.getStartLevel() != null )
                    {
                        provisionFrom.append"@" ).appendprovisionURL.getStartLevel() );
                    }
                    if( !provisionURL.isStart() )
                    {
                        provisionFrom.append"@nostart" );
                    }
                    ifprovisionURL.isUpdate() )
                    {
                        provisionFrom.append"@update" );
                    }
                    arguments.addprovisionFrom.toString() );
                }
            }
        }
        configuration.setAttribute( .toSave );
        configuration.setAttribute( .arguments );
    }
New to GrepCode? Check out our FAQ X