Skip to content

Commit

Permalink
IDE-533
Browse files Browse the repository at this point in the history
  • Loading branch information
gamerson committed Jan 30, 2012
1 parent 476ab2e commit 93035a9
Show file tree
Hide file tree
Showing 2 changed files with 170 additions and 136 deletions.
Expand Up @@ -3,4 +3,5 @@ source.. = src/,\
output.. = bin/
bin.includes = META-INF/,\
.
jars.extra.classpath=platform:/plugin/org.eclipse.sapphire.sdk, platform:/plugin/org.eclipse.sapphire.sdk.build.processor
jars.extra.classpath=platform:/plugin/org.eclipse.sapphire.sdk, platform:/plugin/org.eclipse.sapphire.sdk.build.processor
bin.excludes = rebel.xml
@@ -1,3 +1,20 @@
/*******************************************************************************
* Copyright (c) 2000-2012 Liferay, Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the Free
* Software Foundation; either version 2.1 of the License, or (at your option)
* any later version.
*
* This library is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details.
*
* Contributors:
* Gregory Amerson - initial implementation and ongoing maintenance
*******************************************************************************/

package com.liferay.ide.eclipse.hook.core.model.internal;

import com.liferay.ide.eclipse.hook.core.HookCore;
Expand Down Expand Up @@ -29,94 +46,128 @@
import org.eclipse.sapphire.modeling.ValueBindingImpl;


/**
* @author Gregory Amerson
*/
public class PortalPropertiesBindingImpl extends HookListBindingImpl
{

protected PropertiesConfiguration portalPropertiesConfiguration;

@Override
public void init( IModelElement element, ModelProperty property, String[] params )
private class PortalPropertyResource extends Resource
{
super.init( element, property, params );
private String name;

ModelPropertyListener listener = new ModelPropertyListener()
public PortalPropertyResource( Resource parent )
{
super( parent );
}

@Override
public void handlePropertyChangedEvent( ModelPropertyChangeEvent event )
@Override
protected BindingImpl createBinding( ModelProperty property )
{
if ( property == IPortalProperty.PROP_NAME )
{
updateConfigurationForFile();
return new ValueBindingImpl()
{

@Override
public String read()
{
return getName();
}

@Override
public void write( final String value )
{
setName( value );
}
};
}
};
else if ( property == IPortalProperty.PROP_VALUE )
{
return new ValueBindingImpl()
{

hook().addListener( listener, IHook.PROP_PORTAL_PROPERTIES_FILE.getName() );
@Override
public String read()
{
return getValue() != null ? getValue().toString() : null;
}

updateConfigurationForFile();
}
@Override
public void write( final String value )
{
setValue( value );
}
};
}

protected void updateConfigurationForFile()
{
IFile portalPropertiesFile = getPortalPropertiesFile();
return null;
}

if ( portalPropertiesFile != null && portalPropertiesFile.exists() )
public String getName()
{
try
{
this.portalPropertiesConfiguration = new PortalPropertiesConfiguration();
InputStream is = portalPropertiesFile.getContents();
this.portalPropertiesConfiguration.load( is );
is.close();
}
catch ( Exception e )
{
HookCore.logError( e );
}
return name;
}
}

protected IPortalPropertiesFile getPortalPropertiesFileElement()
{
return hook().getPortalPropertiesFile().element();
}
public Object getValue()
{
if ( PortalPropertiesBindingImpl.this.portalPropertiesConfiguration != null )
{
return PortalPropertiesBindingImpl.this.portalPropertiesConfiguration.getProperty( getName() );
}

protected IFile getPortalPropertiesFile()
{
IPortalPropertiesFile portalPropertiesFileElement = getPortalPropertiesFileElement();
return null;
}

if ( portalPropertiesFileElement != null )
public void setName( String name )
{
Path filePath = portalPropertiesFileElement.getValue().getContent();
Object oldValue = getValue();

for ( IFolder folder : ProjectUtil.getSourceFolders( project() ) )
if ( PortalPropertiesBindingImpl.this.portalPropertiesConfiguration != null )
{
IFile file = folder.getFile( filePath.toPortableString() );
PortalPropertiesBindingImpl.this.portalPropertiesConfiguration.clearProperty( getName() );
}

if ( file.exists() )
{
return file;
}
this.name = name;
setValue( oldValue );
}

public void setValue( Object value )
{
if ( PortalPropertiesBindingImpl.this.portalPropertiesConfiguration != null )
{
PortalPropertiesBindingImpl.this.portalPropertiesConfiguration.setProperty( getName(), value );
flushProperties();
}
}

return null;
}

protected PortalPropertyResource createResource()
{
return new PortalPropertyResource( this.element().resource() );
}
protected PropertiesConfiguration portalPropertiesConfiguration;

@Override
public void remove( Resource resource )
public Resource add( ModelElementType type )
{
if ( resource instanceof PortalPropertyResource )
if ( type.equals( IPortalProperty.TYPE ) )
{
PortalPropertyResource ppResource = (PortalPropertyResource) resource;
this.portalPropertiesConfiguration.clearProperty( ppResource.getName() );
flushProperties();
PortalPropertyResource newResource = createResource();

newResource.setName( "" );
newResource.setValue( "" );

this.element().notifyPropertyChangeListeners( this.property() );

return newResource;
}
else
{
return null;
}
}

this.element().notifyPropertyChangeListeners( this.property() );
protected PortalPropertyResource createResource()
{
return new PortalPropertyResource( this.element().resource() );
}

protected void flushProperties()
Expand All @@ -140,24 +191,51 @@ protected void flushProperties()

}

@Override
public Resource add( ModelElementType type )
protected IFile getPortalPropertiesFile()
{
if ( type.equals( IPortalProperty.TYPE ) )
{
PortalPropertyResource newResource = createResource();
IPortalPropertiesFile portalPropertiesFileElement = getPortalPropertiesFileElement();

newResource.setName( "" );
newResource.setValue( "" );
if ( portalPropertiesFileElement != null )
{
Path filePath = portalPropertiesFileElement.getValue().getContent();

this.element().notifyPropertyChangeListeners( this.property() );
for ( IFolder folder : ProjectUtil.getSourceFolders( project() ) )
{
IFile file = folder.getFile( filePath.toPortableString() );

return newResource;
if ( file.exists() )
{
return file;
}
}
}
else

return null;
}

protected IPortalPropertiesFile getPortalPropertiesFileElement()
{
return hook().getPortalPropertiesFile().element();
}

@Override
public void init( IModelElement element, ModelProperty property, String[] params )
{
super.init( element, property, params );

ModelPropertyListener listener = new ModelPropertyListener()
{
return null;
}

@Override
public void handlePropertyChangedEvent( ModelPropertyChangeEvent event )
{
updateConfigurationForFile();
}
};

hook().addListener( listener, IHook.PROP_PORTAL_PROPERTIES_FILE.getName() );

updateConfigurationForFile();
}

@SuppressWarnings( "rawtypes" )
Expand Down Expand Up @@ -187,88 +265,43 @@ public List<Resource> read()
return properties;
}

@Override
public void remove( Resource resource )
{
if ( resource instanceof PortalPropertyResource )
{
PortalPropertyResource ppResource = (PortalPropertyResource) resource;
this.portalPropertiesConfiguration.clearProperty( ppResource.getName() );
flushProperties();
}

this.element().notifyPropertyChangeListeners( this.property() );
}

@Override
public ModelElementType type( Resource resource )
{
return IPortalProperty.TYPE;
}

private class PortalPropertyResource extends Resource
protected void updateConfigurationForFile()
{
private String name;

public PortalPropertyResource( Resource parent )
{
super( parent );
}
IFile portalPropertiesFile = getPortalPropertiesFile();

@Override
protected BindingImpl createBinding( ModelProperty property )
if ( portalPropertiesFile != null && portalPropertiesFile.exists() )
{
if ( property == IPortalProperty.PROP_NAME )
try
{
return new ValueBindingImpl()
{

@Override
public String read()
{
return getName();
}

@Override
public void write( final String value )
{
setName( value );
}
};
this.portalPropertiesConfiguration = new PortalPropertiesConfiguration();
InputStream is = portalPropertiesFile.getContents();
this.portalPropertiesConfiguration.load( is );
is.close();
}
else if ( property == IPortalProperty.PROP_VALUE )
catch ( Exception e )
{
return new ValueBindingImpl()
{

@Override
public String read()
{
return getValue() != null ? getValue().toString() : null;
}

@Override
public void write( final String value )
{
setValue( value );
}
};
HookCore.logError( e );
}

return null;
}

public String getName()
{
return name;
}

public Object getValue()
{
return PortalPropertiesBindingImpl.this.portalPropertiesConfiguration.getProperty( getName() );
}

public void setName( String name )
{
Object oldValue = getValue();
PortalPropertiesBindingImpl.this.portalPropertiesConfiguration.clearProperty( getName() );
this.name = name;
setValue( oldValue );
}

public void setValue( Object value )
{
PortalPropertiesBindingImpl.this.portalPropertiesConfiguration.setProperty( getName(), value );
flushProperties();
}

}

}

0 comments on commit 93035a9

Please sign in to comment.