Skip to content
This repository has been archived by the owner on Aug 11, 2020. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
MECLIPSE-1836 RemoveResourceLookupPage has similar enablement problem…
…s as the dialog
  • Loading branch information
Milos Kleint authored and rgould committed Oct 18, 2010
1 parent 3f5f5f2 commit 450fc75
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 29 deletions.
Expand Up @@ -398,17 +398,7 @@ protected SwtValidationGroup getLoadButtonValidationGroup()
return loadButtonGroup;
}

/**
* this is the validation group associated with the url input composite.
* @return
* @deprecated
*/
protected SwtValidationGroup getValidationGroup()
{
return getLoadButtonValidationGroup();
}



abstract protected Composite createResourcePanel( Composite parent );

abstract protected void setInput( Object input );
Expand Down
Expand Up @@ -53,6 +53,15 @@ protected Composite createResourcePanel( Composite parent )
{
public void inputChanged( Viewer viewer, Object oldInput, Object newInput )
{
if (newInput == null) {
//just disable finish when no tree content, no error message
getRootValidationGroup().remove(getFinishButtonValidationGroup());
setPageComplete(false);
} else {
getRootValidationGroup().addItem(getFinishButtonValidationGroup(), false);
setPageComplete(true);
getFinishButtonValidationGroup().performValidation();
}
}

public void dispose()
Expand Down Expand Up @@ -157,7 +166,7 @@ public void selectionChanged( SelectionChangedEvent event )
}
} );

getValidationGroup().add( treeViewer, new Validator<ISelection>()
getFinishButtonValidationGroup().add( treeViewer, new Validator<ISelection>()
{
public Class<ISelection> modelType()
{
Expand Down
Expand Up @@ -26,6 +26,7 @@
import org.maven.ide.eclipse.ui.common.ErrorHandlingUtils;
import org.maven.ide.eclipse.ui.common.Messages;
import org.maven.ide.eclipse.ui.common.authentication.UrlInputComposite;
import org.netbeans.validation.api.Problem;
import org.netbeans.validation.api.Problems;
import org.netbeans.validation.api.Severity;
import org.netbeans.validation.api.Validator;
Expand Down Expand Up @@ -61,15 +62,24 @@ abstract public class RemoteResourceLookupPage

private Button loadButton;

private SwtValidationGroup validationGroup;
private SwtValidationGroup loadButtonGroup;

private SwtValidationGroup okButtonGroup;

private SwtValidationGroup rootGroup;

public RemoteResourceLookupPage( String serverUrl )
{
super( RemoteResourceLookupPage.class.getName() );
this.serverUrl = serverUrl;
setPageComplete( false );

validationGroup = SwtValidationGroup.create( SwtValidationUI.createUI( this ) );
loadButtonGroup = SwtValidationGroup.create( new LoadButtonValidationUI() );

rootGroup = SwtValidationGroup.create(SwtValidationUI.createUI(this, SwtValidationUI.MESSAGE));
rootGroup.addItem(loadButtonGroup, false);
okButtonGroup = SwtValidationGroup.create(SwtValidationUI.createUI(this, SwtValidationUI.BUTTON));
rootGroup.addItem(okButtonGroup, false);
}

public void setServerName( String name )
Expand Down Expand Up @@ -114,7 +124,7 @@ public void createControl( Composite parent )

setControl( panel );

validationGroup.performValidation();
rootGroup.performValidation();
if ( serverUrl != null )
{
reload();
Expand All @@ -123,7 +133,7 @@ public void createControl( Composite parent )

protected UrlInputComposite createUrlInputComposite( Composite parent )
{
return new UrlInputComposite( parent, null, getValidationGroup(), UrlInputComposite.ALLOW_ANONYMOUS );
return new UrlInputComposite( parent, null, getLoadButtonValidationGroup(), UrlInputComposite.ALLOW_ANONYMOUS );
}

private void createExpandableComposite( final Composite parent )
Expand Down Expand Up @@ -158,7 +168,7 @@ public void widgetSelected( SelectionEvent e )
}
} );

validationGroup.addItem( new UrlValidationListener( urlInputComposite ), false );
rootGroup.addItem( new UrlValidationListener( urlInputComposite ), false );

String url = urlInputComposite.getUrlText();
if ( url.length() > 0 )
Expand Down Expand Up @@ -192,19 +202,14 @@ protected UrlValidationListener( UrlInputComposite urlInputComposite )
protected void performValidation( Problems problems )
{
String url = urlInputComposite.getUrlText();
if ( url.length() == 0 )
{
loadButton.setEnabled( false );
}
else
if ( url.length() != 0 )
{
if ( !url.equals( serverUrl ) )
{
setInput( input = null );
serverUrl = url;
problems.add( readyToLoadMessage, Severity.FATAL );
problems.add( readyToLoadMessage, Severity.INFO );
}
loadButton.setEnabled( true );
}
}

Expand Down Expand Up @@ -323,7 +328,7 @@ public void run()
else
{
resourceComposite.setFocus();
if ( validationGroup.performValidation() == null )
if ( rootGroup.performValidation() == null )
{
setMessage( message, messageType );
}
Expand All @@ -340,18 +345,54 @@ protected String getServerUrl()
@SuppressWarnings( "unchecked" )
protected void addToValidationGroup( Control control, Validator<String> validator )
{
validationGroup.add( control, validator );
loadButtonGroup.add( control, validator );
}

protected SwtValidationGroup getValidationGroup()
/**
* this is the validation group root validation group, contains the load label group as well..
* and handles error messages
* @return
*/
protected SwtValidationGroup getRootValidationGroup()
{
return validationGroup;
return rootGroup;
}


/**
* this is the validation group associated with the url input composite and handles load button enablement
* @return
*/
protected SwtValidationGroup getLoadButtonValidationGroup()
{
return loadButtonGroup;
}

/**
* this is the validation group for handling the ok/finish button
* @return
*/
protected SwtValidationGroup getFinishButtonValidationGroup()
{
return okButtonGroup;
}

abstract protected Composite createResourcePanel( Composite parent );

abstract protected void setInput( Object input );

abstract protected Object loadResources( String url, IProgressMonitor monitor )
throws Exception;

private class LoadButtonValidationUI implements ValidationUI {

public void showProblem(Problem problem) {
if (loadButton == null) return;
loadButton.setEnabled( !problem.isFatal() );
}

public void clearProblem() {
if (loadButton == null) return;
loadButton.setEnabled( true );
}
};
}

0 comments on commit 450fc75

Please sign in to comment.