Package org.eclipse.sapphire.workspace.internal

Source Code of org.eclipse.sapphire.workspace.internal.ProjectRelativePathValidationService$Condition

/******************************************************************************
* Copyright (c) 2014 Oracle
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
*    Konstantin Komissarchik - initial implementation and ongoing maintenance
******************************************************************************/

package org.eclipse.sapphire.workspace.internal;

import org.eclipse.core.resources.IProject;
import org.eclipse.sapphire.Element;
import org.eclipse.sapphire.LocalizableText;
import org.eclipse.sapphire.Text;
import org.eclipse.sapphire.ValueProperty;
import org.eclipse.sapphire.modeling.Path;
import org.eclipse.sapphire.modeling.Status;
import org.eclipse.sapphire.services.ServiceCondition;
import org.eclipse.sapphire.services.ServiceContext;
import org.eclipse.sapphire.services.ValidationService;
import org.eclipse.sapphire.workspace.ProjectRelativePath;

/**
* @author <a href="mailto:konstantin.komissarchik@oracle.com">Konstantin Komissarchik</a>
*/

public final class ProjectRelativePathValidationService extends ValidationService
{
    @Text( "No context project found" )
    private static LocalizableText message;
   
    static
    {
        LocalizableText.init( ProjectRelativePathValidationService.class );
    }
   
    @Override
    protected Status compute()
    {
        final Element element = context( Element.class );
       
        if( element.property( context( ValueProperty.class ) ).text() != null )
        {
            final IProject project = element.adapt( IProject.class );
           
            if( project == null )
            {
                return Status.createErrorStatus( message.text() );
            }
        }
       
        return Status.createOkStatus();
    }
       
    public static final class Condition extends ServiceCondition
    {
        @Override
        public boolean applicable( final ServiceContext context )
        {
            final ValueProperty property = context.find( ValueProperty.class );
            return ( property != null && Path.class.isAssignableFrom( property.getTypeClass() ) && property.hasAnnotation( ProjectRelativePath.class ) );
        }
    }
   
}
TOP

Related Classes of org.eclipse.sapphire.workspace.internal.ProjectRelativePathValidationService$Condition

TOP
Copyright © 2018 www.massapi.com. 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.