64 changes: 64 additions & 0 deletions at.descher.eclipse.bug397677/src/handlers/SaveHandler.java
@@ -0,0 +1,64 @@
/*******************************************************************************
* Copyright (c) 2010 IBM Corporation and others.
* 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:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package handlers;

import java.lang.reflect.InvocationTargetException;

import javax.inject.Named;

import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.e4.core.contexts.ContextInjectionFactory;
import org.eclipse.e4.core.contexts.IEclipseContext;
import org.eclipse.e4.core.di.annotations.Execute;
import org.eclipse.e4.core.di.annotations.CanExecute;
import org.eclipse.e4.ui.model.application.MContribution;
import org.eclipse.e4.ui.model.application.ui.MDirtyable;
import org.eclipse.e4.ui.services.IServiceConstants;
//import org.eclipse.e4.ui.workbench.Persist;
import org.eclipse.jface.dialogs.ProgressMonitorDialog;
import org.eclipse.jface.operation.IRunnableWithProgress;
import org.eclipse.swt.widgets.Shell;

public class SaveHandler {
@CanExecute
public boolean canExecute(
@Named(IServiceConstants.ACTIVE_PART) MDirtyable dirtyable) {
if (dirtyable == null) {
return false;
}
return dirtyable.isDirty();
}

@Execute
public void execute(
IEclipseContext context,
@Named(IServiceConstants.ACTIVE_SHELL) Shell shell,
@Named(IServiceConstants.ACTIVE_PART) final MContribution contribution)
throws InvocationTargetException, InterruptedException {
final IEclipseContext pmContext = context.createChild();

ProgressMonitorDialog dialog = new ProgressMonitorDialog(shell);
dialog.open();
dialog.run(true, true, new IRunnableWithProgress() {
public void run(IProgressMonitor monitor)
throws InvocationTargetException, InterruptedException {
pmContext.set(IProgressMonitor.class.getName(), monitor);
if (contribution != null) {
Object clientObject = contribution.getObject();
// ContextInjectionFactory.invoke(clientObject, Persist.class, //$NON-NLS-1$
// pmContext, null);
}
}
});

pmContext.dispose();
}
}
47 changes: 47 additions & 0 deletions at.descher.eclipse.bug397677/src/parts/SamplePart.java
@@ -0,0 +1,47 @@
/*******************************************************************************
* Copyright (c) 2010 IBM Corporation and others.
* 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:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package parts;

import javax.annotation.PostConstruct;
import org.eclipse.e4.ui.di.Focus;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;

public class SamplePart {

private Label label;
private TableViewer tableViewer;

@PostConstruct
public void createComposite(Composite parent) {
parent.setLayout(new GridLayout());

label = new Label(parent, SWT.NONE);
label.setText("Sample table");

tableViewer = new TableViewer(parent);
tableViewer.add("Sample item 1");
tableViewer.add("Sample item 2");
tableViewer.add("Sample item 3");
tableViewer.add("Sample item 4");
tableViewer.add("Sample item 5");
tableViewer.getTable().setLayoutData(new GridData(GridData.FILL_BOTH));
}

@Focus
public void setFocus() {
tableViewer.getTable().setFocus();
}
}