Package org.eclipse.sapphire.modeling

Examples of org.eclipse.sapphire.modeling.Path


    {
        for( IProject project : ResourcesPlugin.getWorkspace().getRoot().getProjects() )
        {
            if( project.isAccessible() )
            {
                final Path location = new Path( project.getLocation().toPortableString() );
               
                if( location.isPrefixOf( path ) )
                {
                    return new Path( project.getName() ).append( path.makeRelativeTo( location ) );
                }
            }
        }
       
        return null;
View Full Code Here


            {
                if( project.isAccessible() )
                {
                    if( projectName.equals( project.getName() ) )
                    {
                        return new Path( project.getLocation().toPortableString() ).append( path.removeFirstSegments( 1 ) );
                    }
                }
            }
        }
       
View Full Code Here

    protected boolean computeEnablementState()
    {
        if( super.computeEnablementState() == true )
        {
            final Property property = property();
            final Path relativePath = (Path) ( (Value<?>) property ).content();
           
            if( relativePath != null )
            {
                final Path absolutePath = property.service( RelativePathService.class ).convertToAbsolute( relativePath );
               
                if( absolutePath != null )
                {
                    final File absoluteFile = absolutePath.toFile();
                   
                    if( absoluteFile.exists() && absoluteFile.isFile() )
                    {
                        return true;
                    }
View Full Code Here

    @Override
    protected Object run( final Presentation context )
    {
        final Property property = property();
        final Path relativePath = (Path) ( (Value<?>) property ).content();
       
        if( relativePath != null )
        {
            final Path absolutePath = property.service( RelativePathService.class ).convertToAbsolute( relativePath );
           
            if( absolutePath != null )
            {
                final File file = absolutePath.toFile();
               
                if( file.exists() && file.isFile() )
                {
                    final IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
                   
View Full Code Here

    public void testStringToPath() throws Exception
    {
        final MasterConversionService service = Sapphire.service( MasterConversionService.class );
       
        assertEquals( new Path( "abc" ), service.convert( "abc", Path.class ) );
        assertEquals( new Path( "abc.txt" ), service.convert( "abc.txt", Path.class ) );
        assertEquals( new Path( "folder/abc.txt" ), service.convert( "folder/abc.txt", Path.class ) );
        assertEquals( new Path( "x/y/z/folder/abc.txt" ), service.convert( "x/y/z/folder/abc.txt", Path.class ) );
    }
View Full Code Here

    public void testPathToString() throws Exception
    {
        final MasterConversionService service = Sapphire.service( MasterConversionService.class );
       
        assertEquals( "abc", service.convert( new Path( "abc" ), String.class ) );
        assertEquals( "abc.txt", service.convert( new Path( "abc.txt" ), String.class ) );
        assertEquals( "folder/abc.txt", service.convert( new Path( "folder/abc.txt" ), String.class ) );
        assertEquals( "x/y/z/folder/abc.txt", service.convert( new Path( "x/y/z/folder/abc.txt" ), String.class ) );
    }
View Full Code Here

            dialog.setAllowMultiple( false );
            dialog.setHelpAvailable( false );
            dialog.setInput( input );
            dialog.setComparator( viewerComparator );
           
            final Path currentPathAbsolute = convertToAbsolute( (Path) ( (Value<?>) property ).content() );
           
            if( currentPathAbsolute != null )
            {
                Object initialSelection = null;
               
                if( contentProvider instanceof WorkspaceContentProvider )
                {
                    final URI uri = currentPathAbsolute.toFile().toURI();
                    final IWorkspaceRoot wsroot = ResourcesPlugin.getWorkspace().getRoot();
                   
                    final IFile[] files = wsroot.findFilesForLocationURI( uri );
                   
                    if( files.length > 0 )
                    {
                        final IFile file = files[ 0 ];
                       
                        if( file.exists() )
                        {
                            initialSelection = file;
                        }
                    }
                   
                    if( initialSelection == null )
                    {
                        final IContainer[] containers = wsroot.findContainersForLocationURI( uri );
                       
                        if( containers.length > 0 )
                        {
                            final IContainer container = containers[ 0 ];
                           
                            if( container.exists() )
                            {
                                initialSelection = container;
                            }
                        }                      
                    }
                }
                else
                {
                    initialSelection = ( (FileSystemContentProvider) contentProvider ).find( currentPathAbsolute );
                }
               
                if( initialSelection != null )
                {
                    dialog.setInitialSelection( initialSelection );
                }
            }
           
            if( this.type == FileSystemResourceType.FILE )
            {
                dialog.setValidator( new FileSelectionStatusValidator() );
            }
            else if( this.type == FileSystemResourceType.FOLDER )
            {
                dialog.addFilter( new ContainersOnlyViewerFilter() );
            }
           
            if( ! extensions.isEmpty() )
            {
                dialog.addFilter( new ExtensionBasedViewerFilter( extensions ) );
            }
           
            if( dialog.open() == Window.OK )
            {
                final Object firstResult = dialog.getFirstResult();
               
                if( firstResult instanceof IResource )
                {
                    selectedAbsolutePath = ( (IResource) firstResult ).getLocation().toString();
                }
                else
                {
                    selectedAbsolutePath = ( (FileSystemNode) firstResult ).getFile().getPath();
                }
            }
        }
        else if( this.type == FileSystemResourceType.FOLDER )
        {
            final DirectoryDialog dialog = new DirectoryDialog( p.shell() );
            dialog.setText( property.definition().getLabel( true, CapitalizationType.FIRST_WORD_ONLY, false ) );
            dialog.setMessage( createBrowseDialogMessage( property.definition().getLabel( true, CapitalizationType.NO_CAPS, false ) ) );
           
            final Value<?> value = (Value<?>) property;
            final Path path = (Path) value.content();
           
            if( path != null )
            {
                dialog.setFilterPath( path.toOSString() );
            }
            else if( roots.size() > 0 )
            {
                dialog.setFilterPath( roots.get( 0 ).toOSString() );
            }
           
            selectedAbsolutePath = dialog.open();
        }
        else
        {
            final FileDialog dialog = new FileDialog( p.shell() );
            dialog.setText( property.definition().getLabel( true, CapitalizationType.FIRST_WORD_ONLY, false ) );
           
            final Value<?> value = (Value<?>) property;
            final Path path = (Path) value.content();
           
            if( path != null && path.segmentCount() > 1 )
            {
                dialog.setFilterPath( path.removeLastSegments( 1 ).toOSString() );
                dialog.setFileName( path.lastSegment() );
            }
            else if( roots.size() > 0 )
            {
                dialog.setFilterPath( roots.get( 0 ).toOSString() );
            }
           
            if( ! extensions.isEmpty() )
            {
                final StringBuilder buf = new StringBuilder();
               
                for( String extension : extensions )
                {
                    if( buf.length() > 0 )
                    {
                        buf.append( ';' );
                    }
                   
                    buf.append( "*." );
                    buf.append( extension );
                }
               
                dialog.setFilterExtensions( new String[] { buf.toString() } );
            }
           
            selectedAbsolutePath = dialog.open();
        }
   
        if( selectedAbsolutePath != null )
        {
            final Path relativePath = convertToRelative( new Path( selectedAbsolutePath ) );
           
            if( relativePath != null )
            {
                String result = relativePath.toPortableString();
   
                if( this.includeLeadingSlash )
                {
                    result = "/" + result;
                }
View Full Code Here

                if( enclosed() && path.segmentCount() > 0 && path.segment( 0 ).equals( ".." ) )
                {
                    return null;
                }
               
                Path absolute = null;
               
                for( Path root : getBasePaths() )
                {
                    try
                    {
                        final File file = root.append( path ).toFile().getCanonicalFile();
                        absolute = new Path( file.getPath() );
                       
                        if( file.exists() )
                        {
                            break;
                        }
View Full Code Here

   
    private void testValidationOk( final TestElement element,
                                   final ValueProperty property,
                                   final IPath path )
    {
        element.property( property ).write( new Path( path.toPortableString() ) );
        assertValidationOk( element.property( property ) );
    }
View Full Code Here

    private void testValidationError( final TestElement element,
                                      final ValueProperty property,
                                      final IPath path,
                                      final String expectedErrorMessage )
    {
        element.property( property ).write( new Path( path.toPortableString() ) );
        assertValidationError( element.property( property ), expectedErrorMessage );
    }
View Full Code Here

TOP

Related Classes of org.eclipse.sapphire.modeling.Path

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.