/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2017 Serge Rider (serge@jkiss.org)
*
* 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.jkiss.dbeaver.ext.erd.editor;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.runtime.Path;
import org.eclipse.ui.IElementFactory;
import org.eclipse.ui.IMemento;
import org.jkiss.dbeaver.core.DBeaverCore;
import org.jkiss.utils.CommonUtils;
public class ERDEditorInputFactory implements IElementFactory
{
private static final String ID_FACTORY = ERDEditorInputFactory.class.getName(); //$NON-NLS-1$
private static final String TAG_PATH = "path"; //$NON-NLS-1$
@Override
public IAdaptable createElement(IMemento memento)
{
// Get the file name.
String fileName = memento.getString(TAG_PATH);
if (!CommonUtils.isEmpty(fileName)) {
// Make sure that core is initialized
DBeaverCore.getInstance();
IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(fileName));
if (file != null) {
return new ERDEditorInput(file);
}
}
return null;
}
public static String getFactoryId()
{
return ID_FACTORY;
}
public static void saveState(IMemento memento, ERDEditorInput input)
{
memento.putString(TAG_PATH, input.getFile().getFullPath().toString());
}
}