use of eu.esdihumboldt.hale.ui.service.project.ProjectService in project hale by halestudio.
the class TransformDataWizardSourcePage method createControl.
/**
* @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
*/
@Override
public void createControl(Composite parent) {
Composite content = new Composite(parent, SWT.NONE);
content.setLayout(GridLayoutFactory.swtDefaults().create());
final ListViewer listViewer = new ListViewer(content);
listViewer.getControl().setLayoutData(GridDataFactory.fillDefaults().grab(true, true).create());
if (!useProjectData) {
Button addButton = new Button(content, SWT.PUSH);
addButton.setText("Add source file");
addButton.setLayoutData(GridDataFactory.swtDefaults().align(SWT.END, SWT.CENTER).create());
addButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
InstanceImportWizard importWizard = new InstanceImportWizard();
TransformDataImportAdvisor advisor = new TransformDataImportAdvisor();
// specifying null as actionId results in no call to
// ProjectService.rememberIO
importWizard.setAdvisor(advisor, null);
if (new HaleWizardDialog(getShell(), importWizard).open() == Dialog.OK) {
if (advisor.getInstances() != null) {
sourceCollections.add(advisor.getInstances());
listViewer.add(advisor.getLocation());
getContainer().updateButtons();
}
}
}
});
} else {
// initialize project source data
IRunnableWithProgress op = new IRunnableWithProgress() {
@Override
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
monitor.beginTask("Prepare data sources", IProgressMonitor.UNKNOWN);
ProjectService ps = PlatformUI.getWorkbench().getService(ProjectService.class);
final List<URI> locations = new ArrayList<>();
for (Resource resource : ps.getResources()) {
if (InstanceIO.ACTION_LOAD_SOURCE_DATA.equals(resource.getActionId())) {
// resource is source data
IOConfiguration conf = resource.copyConfiguration(true);
TransformDataImportAdvisor advisor = new TransformDataImportAdvisor();
ProjectResourcesUtil.executeConfiguration(conf, advisor, false, null);
if (advisor.getInstances() != null) {
sourceCollections.add(advisor.getInstances());
locations.add(advisor.getLocation());
}
}
}
PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() {
@Override
public void run() {
for (URI location : locations) {
listViewer.add(location);
}
}
});
monitor.done();
}
};
try {
ThreadProgressMonitor.runWithProgressDialog(op, false);
} catch (Exception e) {
throw new IllegalStateException(e);
}
}
setControl(content);
}
use of eu.esdihumboldt.hale.ui.service.project.ProjectService in project hale by halestudio.
the class ResourcesLabelProvider method getText.
@Override
public String getText(Object element) {
if (element instanceof ProjectToken) {
ProjectService ps = PlatformUI.getWorkbench().getService(ProjectService.class);
String name = ps.getProjectInfo().getName();
if (name == null) {
return "<Unnamed project>";
}
return name;
}
if (element instanceof IOAction) {
IOAction action = (IOAction) element;
// resource category name
if (action.getResourceCategoryName() != null) {
return action.getResourceCategoryName();
}
// action name
if (action.getName() != null) {
return action.getName();
}
// action ID
return action.getId();
}
if (element instanceof Resource) {
Resource resource = (Resource) element;
if (resource.getSource() != null) {
String location = resource.getSource().toString();
int index = location.lastIndexOf('/');
if (index > 0 && index < location.length()) {
return location.substring(index + 1);
} else {
return location;
}
}
return resource.getResourceId();
}
if (element instanceof IContentType) {
IContentType ct = (IContentType) element;
return ct.getName();
}
return element.toString();
}
use of eu.esdihumboldt.hale.ui.service.project.ProjectService in project hale by halestudio.
the class ProjectProperties method refresh.
@Override
public void refresh() {
super.refresh();
ProjectService ps = PlatformUI.getWorkbench().getService(ProjectService.class);
ProjectInfo info = ps.getProjectInfo();
updateProject = false;
nameText.setText((info.getName() == null) ? ("") : (info.getName()));
authorText.setText((info.getAuthor() == null) ? ("") : (info.getAuthor()));
descriptionText.setText((info.getDescription() == null) ? ("") : (info.getDescription()));
updateProject = true;
}
use of eu.esdihumboldt.hale.ui.service.project.ProjectService in project hale by halestudio.
the class ApplicationWorkbenchAdvisor method preShutdown.
/**
* @see WorkbenchAdvisor#preShutdown()
*/
@Override
public boolean preShutdown() {
// call workbench hooks
boolean shutdownCanceled = false;
for (WorkbenchHook hook : hooks) {
try {
if (!hook.preShutdown(getWorkbenchConfigurer().getWorkbench())) {
shutdownCanceled = true;
}
} catch (Exception e) {
e.printStackTrace();
}
}
if (shutdownCanceled) {
return false;
}
// ask for save if there are changes
// TODO use a workbench hook for this
ProjectService ps = PlatformUI.getWorkbench().getService(ProjectService.class);
if (ps.isChanged()) {
Shell shell = PlatformUI.getWorkbench().getWorkbenchWindows()[0].getShell();
MessageBox mb = new MessageBox(shell, SWT.YES | SWT.NO | SWT.CANCEL | SWT.ICON_QUESTION);
// $NON-NLS-1$
mb.setMessage(Messages.ApplicationWorkbenchAdvisor_1);
// $NON-NLS-1$
mb.setText(Messages.ApplicationWorkbenchAdvisor_2);
int result = mb.open();
if (result == SWT.CANCEL) {
return false;
} else if (result == SWT.YES) {
// try saving project
ps.save();
if (ps.isChanged()) {
return false;
}
return true;
} else {
return true;
}
} else {
return true;
}
}
use of eu.esdihumboldt.hale.ui.service.project.ProjectService in project hale by halestudio.
the class LoadProjectAction method run.
/**
* @see org.eclipse.jface.action.Action#run()
*/
@Override
public void run() {
if (Display.getCurrent() == null) {
// execute in display thread
PlatformUI.getWorkbench().getDisplay().asyncExec(this);
return;
}
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell().forceActive();
// close intro if specified and visible
if (closeIntro) {
IIntroPart introPart = PlatformUI.getWorkbench().getIntroManager().getIntro();
if (introPart != null)
PlatformUI.getWorkbench().getIntroManager().closeIntro(introPart);
}
// executes event with last configuration
ProjectService ps = PlatformUI.getWorkbench().getService(ProjectService.class);
// load a given file or show open project dialog
if (path != null) {
if (TYPE_FILE.equalsIgnoreCase(type) || type == null)
ps.load(new File(path).toURI());
else if (TYPE_URI.equalsIgnoreCase(type))
ps.load(URI.create(path));
else if (TYPE_BUNDLE.equalsIgnoreCase(type))
try {
// ps.load(Platform.getBundle(bundle).getEntry(path).toURI());
StringBuilder b = new StringBuilder();
b.append("platform:/plugin/");
b.append(bundle);
if (path.length() > 0 && path.charAt(0) != '/') {
b.append("/");
}
b.append(path);
ps.load(new URI(b.toString()));
} catch (URISyntaxException e) {
throw new IllegalArgumentException(e);
}
} else
ps.open();
}
Aggregations