Skip to content

Commit

Permalink
Add a button to the 'My Heroku Applications' view that allows the use…
Browse files Browse the repository at this point in the history
…r to create a new blank app
  • Loading branch information
jamesward committed Sep 28, 2012
1 parent 90af1a3 commit 119f4cd
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 2 deletions.
Expand Up @@ -455,6 +455,38 @@ public App run() throws HerokuServiceException {
});
}

@Override
public App createApp(final IProgressMonitor pm) throws HerokuServiceException {
return runCancellableOperation(pm, new RunnableWithReturn<App>() {
@Override
public App run() throws HerokuServiceException {
App app = null;

try {
Activator.getDefault().getLogger().log(LogService.LOG_INFO, "creating new blank Heroku App");
app = getOrCreateHerokuSession(pm).createApp(new App());
Map<String, Object> map = new HashMap<String, Object>();
map.put(KEY_APPLICATION_ID, app.getId());

Event event = new Event(TOPIC_APPLICATION_NEW, map);
eventAdmin.postEvent(event);
}
catch (HerokuServiceException e) {
if (e.getErrorCode() == HerokuServiceException.NOT_ACCEPTABLE) {
destroyApplication(pm, app);
throw e;
}
else {
Activator.getDefault().getLogger().log(LogService.LOG_WARNING, "unknown error when creating app, dying ...");
throw e;
}
}

return app;
}
});
}

@Override
public boolean materializeGitApp(IProgressMonitor pm, App app, IMPORT_TYPES importType, IProject existingProject, String gitLocation, int timeout,
String dialogTitle, CredentialsProvider cred, String transportErrorMessage) throws HerokuServiceException {
Expand Down
Expand Up @@ -276,6 +276,17 @@ public static enum IMPORT_TYPES {
*/
public App createAppFromTemplate(IProgressMonitor pm, String appName, String templateName) throws HerokuServiceException;

/**
* Creates a new blank app
*
* @param pm
* the progress monitor
* @return the newly created App
* @throws HerokuServiceException
* if there are network problems
*/
public App createApp(IProgressMonitor pm) throws HerokuServiceException;

/**
* Materializes the given app in the user's local git repository and in the
* workspace. If an existing Eclipse project is given, the materialized git
Expand Down
2 changes: 1 addition & 1 deletion com.heroku.eclipse.ui/i18n/messages.properties
Expand Up @@ -201,6 +201,6 @@ HerokuAppManagerViewPart_Scale_Error_UnknownDyno_Title=Unknown process type
HerokuAppManagerViewPart_Scale_Error_UnknownDyno=Unknown process type: ''{0}''
HerokuAppManagerViewPart_AppConsole_Title=Heroku - {0}
HerokuAppManagerViewPart_ProcConsole_Title=Heroku - {0}/{1}

HerokuAppManagerViewPart_Create=Create a New Blank App


Expand Up @@ -43,6 +43,7 @@
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
Expand Down Expand Up @@ -104,6 +105,8 @@ public class HerokuApplicationManagerViewPart extends ViewPart implements Websit

private TreeViewer viewer;

private Button footerButton;

private static HerokuServices herokuService;

private List<ServiceRegistration<EventHandler>> handlerRegistrations;
Expand All @@ -126,14 +129,28 @@ public void init(IViewSite site, IMemento memento) throws PartInitException {
}

public void createPartControl(Composite parent) {
viewer = new TreeViewer(parent, SWT.SINGLE | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION);
Composite container = new Composite(parent, SWT.NONE);
GridLayout gridLayout = new GridLayout();
gridLayout.numColumns = 1;
container.setLayout(gridLayout);

viewer = new TreeViewer(container, SWT.SINGLE | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION);
viewer.setContentProvider(new ContentProviderImpl());
viewer.getTree().setHeaderVisible(true);
viewer.getTree().setLinesVisible(true);
viewer.getTree().setData(HerokuServices.ROOT_WIDGET_ID, HerokuViewConstants.V_APPS_LIST);
viewer.setComparer(new ElementComparerImpl());
viewer.setComparator(new AppComparator());

GridData viewerGridData = new GridData();
viewerGridData.verticalAlignment = GridData.FILL;
viewerGridData.verticalSpan = 2;
viewerGridData.grabExcessVerticalSpace = true;
viewerGridData.horizontalAlignment = GridData.FILL;
viewerGridData.grabExcessHorizontalSpace = true;

viewer.getTree().setLayoutData(viewerGridData);

{
nameColumn = new TreeViewerColumn(viewer, SWT.NONE);
nameColumn.setLabelProvider(LabelProviderFactory.createApp_Name());
Expand Down Expand Up @@ -197,6 +214,24 @@ public void open(OpenEvent event) {

refreshApplications(new NullProgressMonitor(), false);
subscribeToEvents();

footerButton = new Button(container, SWT.NONE);
GridData footerGridData = new GridData();
footerGridData.horizontalAlignment = SWT.CENTER;
footerButton.setLayoutData(footerGridData);
footerButton.setText(Messages.getString("HerokuAppManagerViewPart_Create"));
footerButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
try {
// create the app
Activator.getDefault().getService().createApp(new NullProgressMonitor());
}
catch (HerokuServiceException e1) {
HerokuUtils.herokuError(footerButton.getShell(), e1);
}
}
});
}

private void createToolbar() {
Expand Down

0 comments on commit 119f4cd

Please sign in to comment.