eclipse plugin: Tweak a bit the layout and...
...the functionality of the addon manager
This commit is contained in:
parent
4a84b4278d
commit
f8a903d4e4
1 changed files with 106 additions and 82 deletions
|
@ -56,84 +56,81 @@ public class AddonsView extends ViewPart
|
|||
|
||||
public AddonsView()
|
||||
{
|
||||
ports_ = new ArrayList<String>();
|
||||
ports_ = new ArrayList<String>( );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createPartControl( Composite parent )
|
||||
{
|
||||
parent.setLayout(new FillLayout(SWT.VERTICAL));
|
||||
parent.setLayout(new FillLayout(SWT.HORIZONTAL));
|
||||
|
||||
Composite composite = new Composite(parent, SWT.NONE);
|
||||
composite.setLayout(new GridLayout(2, false));
|
||||
Group grpAddonsList = new Group( parent, SWT.NONE );
|
||||
grpAddonsList.setText( "Addons list" );
|
||||
grpAddonsList.setLayout( new FillLayout( SWT.HORIZONTAL ) );
|
||||
|
||||
Label lblSelectAddonServer = new Label(composite, SWT.NONE);
|
||||
lblSelectAddonServer.setText("Select addon server: ");
|
||||
table_ = new Table( grpAddonsList, SWT.BORDER | SWT.FULL_SELECTION );
|
||||
table_.setHeaderVisible( true );
|
||||
table_.setLinesVisible( true );
|
||||
|
||||
cmbAddonServer_ = new Combo(composite, SWT.NONE);
|
||||
cmbAddonServer_.addSelectionListener(new SelectionAdapter() {
|
||||
TableColumn tblclmnType = new TableColumn( table_, SWT.NONE );
|
||||
tblclmnType.setWidth( 92 );
|
||||
tblclmnType.setText( "Type" );
|
||||
|
||||
TableColumn tblclmnAddonName = new TableColumn( table_, SWT.NONE );
|
||||
tblclmnAddonName.setWidth( 100 );
|
||||
tblclmnAddonName.setText( "Addon Name" );
|
||||
|
||||
TableColumn tblclmnAddonTitle = new TableColumn( table_, SWT.NONE );
|
||||
tblclmnAddonTitle.setWidth( 121 );
|
||||
tblclmnAddonTitle.setText( "Addon Title" );
|
||||
|
||||
TableColumn tblclmnAuthors = new TableColumn( table_, SWT.NONE );
|
||||
tblclmnAuthors.setWidth( 139 );
|
||||
tblclmnAuthors.setText( "Author(s)" );
|
||||
|
||||
TableColumn tblclmnVersion = new TableColumn( table_, SWT.NONE );
|
||||
tblclmnVersion.setWidth( 100 );
|
||||
tblclmnVersion.setText( "Version" );
|
||||
|
||||
TableColumn tblclmnDownloads = new TableColumn( table_, SWT.NONE );
|
||||
tblclmnDownloads.setWidth( 100 );
|
||||
tblclmnDownloads.setText( "Downloads" );
|
||||
|
||||
Group grpOptions = new Group( parent, SWT.NONE );
|
||||
grpOptions.setText( "Options" );
|
||||
grpOptions.setLayout( new GridLayout( 2, false ) );
|
||||
|
||||
Label lblSelectAddonServer = new Label( grpOptions, SWT.NONE );
|
||||
lblSelectAddonServer.setText( "Select addon server: " );
|
||||
|
||||
cmbAddonServer_ = new Combo( grpOptions, SWT.NONE );
|
||||
GridData gd_cmbAddonServer = new GridData( SWT.FILL, SWT.FILL, false, false, 1, 1 );
|
||||
gd_cmbAddonServer.widthHint = 148;
|
||||
cmbAddonServer_.setLayoutData( gd_cmbAddonServer );
|
||||
|
||||
cmbAddonServer_.addSelectionListener( new SelectionAdapter( ) {
|
||||
@Override
|
||||
public void widgetSelected(SelectionEvent e) {
|
||||
if ( e.getSource( ) instanceof Combo == false)
|
||||
public void widgetSelected( SelectionEvent e )
|
||||
{
|
||||
if ( e.getSource( ) instanceof Combo == false )
|
||||
return;
|
||||
|
||||
Combo combo = (Combo) e.getSource( );
|
||||
Combo combo = ( Combo ) e.getSource( );
|
||||
if ( combo.getSelectionIndex( ) == -1 )
|
||||
return;
|
||||
|
||||
currentPort_ = ports_.get( combo.getSelectionIndex( ) );
|
||||
refreshAddons();
|
||||
refreshAddons( );
|
||||
}
|
||||
});
|
||||
|
||||
GridData gd_cmbAddonServer = new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1);
|
||||
gd_cmbAddonServer.widthHint = 267;
|
||||
cmbAddonServer_.setLayoutData(gd_cmbAddonServer);
|
||||
|
||||
Group grpAddonsList = new Group(composite, SWT.NONE);
|
||||
grpAddonsList.setText("Addons list");
|
||||
grpAddonsList.setLayout(new FillLayout(SWT.HORIZONTAL));
|
||||
GridData gd_grpAddonsList = new GridData(SWT.FILL, SWT.CENTER, false, false, 2, 1);
|
||||
gd_grpAddonsList.heightHint = 105;
|
||||
gd_grpAddonsList.widthHint = 579;
|
||||
grpAddonsList.setLayoutData(gd_grpAddonsList);
|
||||
|
||||
table_ = new Table(grpAddonsList, SWT.BORDER | SWT.FULL_SELECTION);
|
||||
table_.setHeaderVisible(true);
|
||||
table_.setLinesVisible(true);
|
||||
|
||||
TableColumn tblclmnType = new TableColumn(table_, SWT.NONE);
|
||||
tblclmnType.setWidth(92);
|
||||
tblclmnType.setText("Type");
|
||||
|
||||
TableColumn tblclmnAddonName = new TableColumn(table_, SWT.NONE);
|
||||
tblclmnAddonName.setWidth(100);
|
||||
tblclmnAddonName.setText("Addon Name");
|
||||
|
||||
TableColumn tblclmnAddonTitle = new TableColumn(table_, SWT.NONE);
|
||||
tblclmnAddonTitle.setWidth(121);
|
||||
tblclmnAddonTitle.setText("Addon Title");
|
||||
|
||||
TableColumn tblclmnAuthors = new TableColumn(table_, SWT.NONE);
|
||||
tblclmnAuthors.setWidth(139);
|
||||
tblclmnAuthors.setText("Author(s)");
|
||||
|
||||
TableColumn tblclmnVersion = new TableColumn(table_, SWT.NONE);
|
||||
tblclmnVersion.setWidth(100);
|
||||
tblclmnVersion.setText("Version");
|
||||
|
||||
TableColumn tblclmnDownloads = new TableColumn(table_, SWT.NONE);
|
||||
tblclmnDownloads.setWidth(100);
|
||||
tblclmnDownloads.setText("Downloads");
|
||||
} );
|
||||
|
||||
ports_.clear( );
|
||||
// fill the addons
|
||||
for ( Entry<String, String> server :
|
||||
AddonUploadPreferencePage.ADDON_SERVER_PORTS.entrySet( ) ) {
|
||||
AddonUploadPreferencePage.ADDON_SERVER_PORTS.entrySet( ) ) {
|
||||
|
||||
cmbAddonServer_.add( String.format( "%s ( port: %s )"
|
||||
, server.getValue( )
|
||||
, server.getKey( ) ) );
|
||||
cmbAddonServer_.add( String.format(
|
||||
"%s ( port: %s )", server.getValue( ), server.getKey( ) ) );
|
||||
ports_.add( server.getKey( ) );
|
||||
}
|
||||
}
|
||||
|
@ -149,9 +146,10 @@ public class AddonsView extends ViewPart
|
|||
}
|
||||
|
||||
loading_ = true;
|
||||
table_.setItemCount( 0 );
|
||||
table_.clearAll( );
|
||||
|
||||
if ( ! StringUtils.isNullOrEmpty( currentPort_ ) ) {
|
||||
if ( !StringUtils.isNullOrEmpty( currentPort_ ) ) {
|
||||
WorkspaceJob loadAddons = new WorkspaceJob( "Retrieving list..." ) {
|
||||
|
||||
@Override
|
||||
|
@ -160,25 +158,54 @@ public class AddonsView extends ViewPart
|
|||
monitor.beginTask( "Retrieving list...", 100 );
|
||||
String installName = "";
|
||||
|
||||
OutputStream stderr = GUIUtils.createConsole(
|
||||
"Wesnoth Addon Manager", null, false ).newOutputStream( );
|
||||
OutputStream stderr = GUIUtils
|
||||
.createConsole( "Wesnoth Addon Manager", null, false )
|
||||
.newOutputStream( );
|
||||
|
||||
ExternalToolInvoker tool = WMLTools.runWesnothAddonManager(
|
||||
installName,
|
||||
null,
|
||||
currentPort_,
|
||||
Arrays.asList( "-l" ), // list addons
|
||||
null,
|
||||
new OutputStream[] { stderr } );
|
||||
installName, null, currentPort_,
|
||||
Arrays.asList( "-w", "-l" ), // list addons in raw mode
|
||||
null, new OutputStream[] { stderr } );
|
||||
tool.waitForTool( );
|
||||
|
||||
/**
|
||||
* parse the contents
|
||||
* columns = [["type", "name", "title", "author",
|
||||
* "version", "uploads", "downloads",
|
||||
* "size", "timestamp", "translate"]]
|
||||
* parse the contents columns = [[" 0 - type", "1 - name",
|
||||
* "2 - title", "3 - author", "4 - version", "uploads",
|
||||
* "5 - downloads", "size", "timestamp", "translate"]]
|
||||
*/
|
||||
final String[] lines = StringUtils.getLines( tool.getOutputContent( ) );
|
||||
final List<String[]> addons = new ArrayList<String[]>( );
|
||||
|
||||
String[] tmpColumns = null;
|
||||
int index = -1;
|
||||
|
||||
for ( String line : lines ) {
|
||||
index = -1;
|
||||
|
||||
if ( line.startsWith( "\\ campaign" ) ) {
|
||||
if ( tmpColumns != null )
|
||||
addons.add( tmpColumns );
|
||||
tmpColumns = new String[6];
|
||||
} else if ( line.startsWith( " \\ type" ) )
|
||||
index = 0;
|
||||
else if ( line.startsWith( " \\ name" ) )
|
||||
index = 1;
|
||||
else if ( line.startsWith( " \\ title" ) )
|
||||
index = 2;
|
||||
else if ( line.startsWith( " \\ author" ) )
|
||||
index = 3;
|
||||
else if ( line.startsWith( " \\ version" ) )
|
||||
index = 4;
|
||||
else if ( line.startsWith( " \\ downloads" ) )
|
||||
index = 5;
|
||||
|
||||
// got something interesting? parse it
|
||||
if ( tmpColumns != null && index != -1 ) {
|
||||
tmpColumns[index] = line.substring(
|
||||
line.indexOf( '\'' ) + 1,
|
||||
line.lastIndexOf( '\'' ) ).trim( );
|
||||
}
|
||||
}
|
||||
|
||||
// need GUI Thread access
|
||||
Display.getDefault( ).syncExec( new Runnable( ) {
|
||||
|
@ -186,23 +213,20 @@ public class AddonsView extends ViewPart
|
|||
public void run()
|
||||
{
|
||||
// skipp 1st line since it's just the header
|
||||
for ( int i = 1; i < lines.length; ++i ) {
|
||||
String[] columns = lines[i].split( " +" );
|
||||
//System.out.println( columns );
|
||||
for ( String[] addon : addons ) {
|
||||
|
||||
TableItem tableItem= new TableItem(table_, SWT.NONE);
|
||||
TableItem tableItem = new TableItem( table_, SWT.NONE );
|
||||
tableItem.setText( new String[] {
|
||||
columns[0],
|
||||
columns[1],
|
||||
columns[2],
|
||||
columns[3],
|
||||
columns[4],
|
||||
columns[6]
|
||||
});
|
||||
addon[0],
|
||||
addon[1],
|
||||
addon[2],
|
||||
addon[3],
|
||||
addon[4],
|
||||
addon[5] } );
|
||||
|
||||
}
|
||||
}
|
||||
});
|
||||
} );
|
||||
loading_ = false;
|
||||
|
||||
monitor.worked( 100 );
|
||||
|
|
Loading…
Add table
Reference in a new issue