Skip to content
Snippets Groups Projects
Commit df856ac0 authored by Daniel Ratiu's avatar Daniel Ratiu
Browse files

refactorings of the components library, close to adding the TypeDefinition objects to the library

refs 1369
parent e751d3bb
No related branches found
No related tags found
No related merge requests found
......@@ -27,6 +27,7 @@ Export-Package: org.fortiss.tooling.base.ui,
org.fortiss.tooling.base.ui.editpart.request,
org.fortiss.tooling.base.ui.fieldassist,
org.fortiss.tooling.base.ui.layout,
org.fortiss.tooling.base.ui.library,
org.fortiss.tooling.base.ui.preferences,
org.fortiss.tooling.base.ui.properties.view,
org.fortiss.tooling.base.ui.tablecell,
......
/*--------------------------------------------------------------------------+
$Id: codetemplates.xml 1 2011-01-01 00:00:01Z hoelzl $
| |
| Copyright 2013 ForTISS GmbH |
| |
| Licensed under the Apache License, Version 2.0 (the "License"); |
| you may not use this file except in compliance with the License. |
| You may obtain a copy of the License at |
| |
| http://www.apache.org/licenses/LICENSE-2.0 |
| |
| Unless required by applicable law or agreed to in writing, software |
| distributed under the License is distributed on an "AS IS" BASIS, |
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| See the License for the specific language governing permissions and |
| limitations under the License. |
+--------------------------------------------------------------------------*/
package org.fortiss.tooling.base.ui.library;
import static org.conqat.ide.commons.ui.dialog.MessageUtils.showErrorAsync;
import static org.fortiss.tooling.base.ui.library.LibrarySelectionDialog.openLibraryPackageDialog;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.ActionContributionItem;
import org.eclipse.jface.action.IContributionItem;
import org.fortiss.tooling.base.library.ModelElementLibraryService;
import org.fortiss.tooling.base.ui.ToolingBaseUIActivator;
import org.fortiss.tooling.kernel.model.ILibraryElementReference;
import org.fortiss.tooling.kernel.model.ILibraryPackage;
import org.fortiss.tooling.kernel.model.INamedElement;
import org.fortiss.tooling.kernel.ui.extension.IContextMenuContributor;
import org.fortiss.tooling.kernel.ui.extension.data.ContextMenuContextProvider;
import org.fortiss.tooling.kernel.ui.service.IContextMenuService;
/**
* Base class for adding elements to a library.
*
* T - the type of the element to be added to the library
*
* @author ratiu
* @author $Author: hoelzl $
* @version $Rev: 18709 $
* @ConQAT.Rating RED Hash:
*/
public abstract class AddElementToLibraryBase<T extends INamedElement> implements
IContextMenuContributor {
/** {@inheritDoc} */
@Override
public List<IContributionItem> getContributedItems(EObject selection,
ContextMenuContextProvider contextProvider) {
if(getElementClass().isAssignableFrom(selection.getClass()) &&
!(selection instanceof ILibraryElementReference)) {
INamedElement selectedNamedElement = (INamedElement)selection;
AddToLibraryAction action = new AddToLibraryAction(selectedNamedElement);
List<IContributionItem> contributionItems = new ArrayList<IContributionItem>();
contributionItems.add(new ActionContributionItem(action));
return contributionItems;
}
return Collections.emptyList();
}
/** {@inheritDoc} */
@Override
public String getMenuSectionID() {
return IContextMenuService.AFTER_GLOBAL_MENU_SECTION_ID;
}
/** Returns the class of the element that could be added to the library. */
protected abstract <S extends INamedElement> Class<S> getElementClass();
/**
* Returns the class of a library package that should contain elements of type given by
* {@link #getElementClass()}.
*/
protected abstract <S extends ILibraryPackage> Class<S> getLibraryPackageClass();
/**
* The action.
*
* @author ratiu
* @author $Author: ratiu $
* @version $Rev: 18709 $
* @ConQAT.Rating RED Hash:
*/
private class AddToLibraryAction extends Action {
/** The selected element. */
private INamedElement selectedElement;
/** Constructor. */
AddToLibraryAction(INamedElement selectedElement) {
super("Add to Library", ToolingBaseUIActivator.getImageDescriptor("icons/library.png"));
this.selectedElement = selectedElement;
}
/** {@inheritDoc} */
@Override
public void run() {
String msg = checkLibrarySupported(selectedElement);
if(msg != null) {
showErrorAsync("Unsupported Operation", msg);
return;
}
final ILibraryPackage pack = openLibraryPackageDialog(getLibraryPackageClass());
if(pack != null) {
ModelElementLibraryService.INSTANCE.addElementToLibrary(pack, selectedElement);
}
}
/**
* Checks if this element can be added to the library. Returns null if the element can
* be added to the library and an explanation string otherwise.
*/
protected String checkLibrarySupported(@SuppressWarnings("unused") INamedElement element) {
return null;
}
}
}
/*--------------------------------------------------------------------------+
$Id: codetemplates.xml 1 2011-01-01 00:00:01Z hoelzl $
| |
| Copyright 2012 ForTISS GmbH |
| |
| Licensed under the Apache License, Version 2.0 (the "License"); |
| you may not use this file except in compliance with the License. |
| You may obtain a copy of the License at |
| |
| http://www.apache.org/licenses/LICENSE-2.0 |
| |
| Unless required by applicable law or agreed to in writing, software |
| distributed under the License is distributed on an "AS IS" BASIS, |
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| See the License for the specific language governing permissions and |
| limitations under the License. |
+--------------------------------------------------------------------------*/
package org.fortiss.tooling.base.ui.library;
import static org.fortiss.tooling.kernel.utils.EcoreUtils.pickInstanceOf;
import java.util.List;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.jface.window.Window;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.PlatformUI;
import org.fortiss.tooling.base.ui.dialog.ElementTreeSingleSelectDialog;
import org.fortiss.tooling.base.ui.dialog.ModelElementTreeContentProvider;
import org.fortiss.tooling.kernel.model.ILibrary;
import org.fortiss.tooling.kernel.model.ILibraryPackage;
import org.fortiss.tooling.kernel.service.ILibraryService;
import org.fortiss.tooling.kernel.ui.presentation.ModelElementLabelProvider;
/**
* Provides a dialog for selecting an library package.
*
* @author ratiu
* @author $Author: hoelzl $
* @version $Rev: 18709 $
* @ConQAT.Rating GREEN Hash: A465072E6E1EDDB6760A5D2AE1CD9999
*/
public class LibrarySelectionDialog {
/** Opens a dialog to select the library root. */
@SuppressWarnings("unchecked")
public static <T extends ILibraryPackage> T openLibraryPackageDialog(
final Class<T> libraryPackageClass) {
Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
List<ILibrary> allLibs = ILibraryService.INSTANCE.getLibrariesFromWorkspace();
ElementTreeSingleSelectDialog dialog =
new ElementTreeSingleSelectDialog(shell, "Library package selection",
"Please select a package where the element should be placed", allLibs,
null, new ModelElementTreeContentProvider(allLibs) {
/** {@inheritDoc} */
@Override
public List<? extends EObject> getChildren(EObject parent) {
return pickInstanceOf(libraryPackageClass,
super.getChildren(parent));
}
}, new ModelElementLabelProvider(), null) {
/** {@inheritDoc} */
@Override
public boolean acceptElement(Object element) {
return element instanceof ILibraryPackage;
}
};
if(Window.OK == dialog.open()) {
Object selectedElement = dialog.getSelectedElement();
if(libraryPackageClass.isAssignableFrom(selectedElement.getClass())) {
return (T)selectedElement;
}
}
return null;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment